Bootstrapping synced managers

Hi everyone!

How do I create a synced “manager-like” prefab?

I would like to achieve something analogous to the sample scene 7_PlayerSpawner’s SpawnManager.cs (version 1.8). However, the SpawnManager listens to onLiveQuerySynced which only seems to work when the clients are connecting. In my case, the clients have been connected already and are loading into the gameplay scene.

I’ve been struggling to find something I can “hook on” to make sure I only run its logic in one of the clients.

Hey! There is currently no event that let’s you detect unique entity resolution post-connection, this is a feature that has been added to our backlog.

Meanwhile, try adding this to your GameManager as a workaround:

private CoherenceSync sync;

public void OnEnable()
{
sync = GetComponent();
sync.OnStateRemote.AddListener(OnStateRemote);
}
public void OnDisable()
{
sync.OnStateRemote.RemoveListener(OnStateRemote);
}

public void OnStateRemote()
{
Debug.Log(“This is NOT the real GameManager.”);
sync.SendCommand(OnUniquenessResolved, MessageTarget.AuthorityOnly);
}

[Command(defaultRouting = MessageTarget.AuthorityOnly)]
public void OnUniquenessResolved()
{
Debug.Log(“This is the real GameManager.”);

/* Start GameManaging here */

}

Thanks, @Mathias!

I have a follow up question on this: How to handle the case of only existing one player in the session? OnUniquenessResolved would never be solved.

I tried to use ConnectedClients, but I observed that this information is lost on scene transition. Clients are still connected and all entities are obserbed by all clients as expected, but the bridge only displays one ConnectedClient (the local client one). Is this expected? Maybe I messed up something in my scene transition flow.