Scene Transition Flow

I implemented a scene transition in my game, and it seems to be working but I suspect that I’ve messed up something.

Here is my scene flow:

  1. Application starts and before loading the first scene, Reflex (https://github.com/gustavopsantos/Reflex) does the following:

    1. Instantiate CoherenceBridge with Don’tDestroyOnLoad, enabled ClientConnection, enabled Create Global Query, enabled Main Bridge and enabled Use Build Index As Scene Id.

    2. Registers the instantiated bridge to the BridgeResolve.

    3. Registers a callback to sceneLoaded that calls SetClientScene and the instantiation scene.

  2. Unity loads the first scene (MainMenu), which has a CoherenceBridge of its own, but I guess it just “writes its values” into the main bridge

  3. In that scene, I am using the Room UI sample to create and join a room. I add a listener to CoherenceBridge.onConnect, and when it is invoked, I call SceneManager.LoadScene

    1. When the scene loads, I observe that all but one ClientConnections except one ( I guess the local connection) disappears.
  4. In the next loaded scenes

    1. Clients are able to instantiate CoherenceSyncs and Coherence spawns the remote objects in all clients as expected.

    2. Unique CoherenceSyncs (such as the one mentioned here Bootstrapping synced managers ) generate the following error when the second client joins “ ERR create entity request failed error=“can not create duplicate entities in different scenes, rejecting: [abs_ent 12 (0)] → UUID: level (1 != 2)” logId=37 logger=entityManager project-id=local room-uid=374813279” but it works anyway just as I would expect.

I’m using shared authority and running a local server. All scenes have a CoherenceBridge and a CoherenceLiveQuery (and I’ve also read Scene management :grin: )

Thanks!

Hey so some questions to help me understand what’s up:
Do you expect to use scenes as a way of segregating networked entities? Like, two clients connect to the same replication server but are in different scenes so they can’t see each other’s entities?

Generally, I expect to see that error if client 1 creates the unique entity A in scene 1 and client 2 creates the same unique entity A in scene 2. It’s possible that there is a race with the connection and changing scenes and instantiating that is causing this that you’ll need to account for.

I suggest:

  • don’t use the scene indexing (SetClientScene) unless you actually want to have players on the same replication server in different scenes (this is kind of a complex setup with limited value compared to just having each scene have a separate bridge like if I’m in dungeon A and you’re in dungeon B we’re in different rooms on the replication server)
  • if you do want to use the scene index stuff, then make sure that all clients are in the same scene index when you instantiate the unique entities. (it looks like one client is in scene 1 and the other in scene 2 instantiating the same entity which is a no no unless you’re using the separate bridges concept)

Otherwise your setup sounds reasonable and you’re right about #2, when you have a main bridge and then load a scene with it’s own bridge it informs the main bridge that this is the scene you want to instantiate things into which is nice if you use multi scene setup for things like separating UI or other things and don’t want a mono-scene.

Do you expect to use scenes as a way of segregating networked entities? Like, two clients connect to the same replication server but are in different scenes so they can’t see each other’s entities?

I would like the clients to always move together between scenes.

I have removed the scene indexing (SetClientScene and InstantiationScene), but the error log still persists.

Not sure how I would make sure the unique entities are instantiated when all clients are in the same scene as the the unique entity is serialized in the scene. One of the clients will load first.

If you’re still getting the duplicate instances in different scenes error from the RS then you must still have a bridge that is setting the build index. Make sure these are not set:

1 Like

I see.. I unchecked “Use Build Index As Scene Id” and left Scene identifier as 0 in all the CoherenceBridges. Now the error log from the runner disappeared, but I started to get a few different errors.

1- Now sometimes when changing scenes, I get the following error

When this occurs, I stop seeing other clients in the “Client Connections” list on the client that this has happened. I can however, still see all the entities from all clients as expected.

Also, when leaving the scene, I observed that Coherence is Instantiating the objects from the leaving scene again, even if they do not have a CoherenceSync component.

2- After moving from a scene GameSetup to a scene Sandbox, I am observing that objects instantiated at runtime from a previous scene GameSetup are also getting their initialization called unity events called AND getting disabled? (I think perhaps also getting destroyed?)

(Nevermind the missing behaviour warnings. They are still leftovers from Netcode for GameObjects that I’m cleaning up xD)

I feel like the DI is doing something that coherence doesn’t like. Is it possible that reflex is somehow instantiating multiple bridges so more than one connection entity is being created or something? This callstack in particular is concerning.

the entity is created by the network and then DI does… something … to it and then you get the errors in the post network entity creation actions. What does install bindings do to an instantiated network entity? Is it somehow assigning it to the wrong bridge by doing things with bridge resolve? If so, that’s a problem. The bridge is already resolved since it’s the one that is creating this thing in the first place.

Well, that is the confusing part. Install bindings don’t do anything directly on instantiated network entities. The GameObject instantiated by coherence on the logs image does not have a CoherenceSync and it is not part of any synced prefab.

Install bindings in Reflex just means registering references in the scene DI container.

So…I’ve separated the issues so we can address them one by one. Focusing on the error from the first image I shared:

I removed every GameObject from the GameSetup except one with a CoherenceBridge and another with the CoherenceLiveQuery. Still, I get the same error when loading the scene. I only get the error on the second client that joins the room.

Error log from the second client that joined the room and its Main bridge in the inspector:

Main bridge of the client that created and joined the room first (after the second client joined):

The order order of events is:

1- First client creates and joins room.

2- First clients loads the “GameSetup“ scene

3- Second client joins room

4- Second client loads the “GameSetup“ scene

Just some extra info:

This is the Coherence Main Bridge prefab I’m using

And this one is the CoherenceBridge added to the GameSetup scene:

What does the “ToolkitClientConnectionManagerFailedToAddConnection” error means?

Adding two different game executions with log mode set to Debug:

  • The issue happening on the perspective of the first client to create and join the room:

  • The issue happening on the perspective of the client that joined the room: