Synced Scene Loading

Hey everyone!

Currently in the game I’m working on, I would like to “move” all clients (load another scene) but I’m observing, and inferring, that as the clients load the new scene they destroy their current synced objects in different orders and start syncing objects on the new scene in different orders.

That causes a few issues like clients destroying objects they don’t own then Coherence recreates them to destroy right after when the owner client unloads the scene and destroy it on their side. Even more problematic for me, objects serialized in the next scene spawning on the clients that haven’t left the previous scene causing SerializedFields to not be there and injection to fail.

The options I currently see forward are:

1- Each scene has a separate bridge, and whenever players move between scenes they disconnect, store whatever data they need to “reconstruct” the session and connect again on the new bridge using the data stored.

2 - Use SetClientScene, but apparently that is an even more complicated setup. Especially because having unique objects serialized in the scene breaks it as the object instantiates with the scene loading.

3 - Implementing some kind of “synced scene load controller”, not having any CoherenceSync on the scene so I can control when things are loading, and not using injection scoped to the scene because the objects I might need to register to the container won’t be there at scene load.

I am not happy with any of the three approaches, and I feel like I’m missing an obvious way of doing this. How should I approach this case?

Hi Erethan,

If I understand correctly, all your clients are supposed to be in the same scene at all times, rather than in different scenes. If so, you don’t need to use client scenes.

In your case, however, some coordination between the clients will be needed to transition between scenes. Assuming one client acts as a host, here are some guidelines on how you could handle scenes changes:

  • The host client should initiate the level load and instruct the other clients to do the same, sending a command to them.
  • You might use an intermediate loading scene and client connections to share the loading state of clients with each other: menu, loading, scene loaded… Wait for everyone to be ready to start the game.
  • Use queries and activate/deactivate them to control remote entity instantiation. The query should only be activated when the client is in the game scene, which prevents remote spawns during the transition.

I hope this helps you.

1 Like

I think leveraging queries is the key thing I was missing. Sounds promissing

Thanks, @benito_coh!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.