Hey, I’m trying the switch the scene when the lobby owner presses a “start game” button. I’m using NGO 1.11.0 with the Facepunch Transport.
For switching the scene I use this:
public void LoadScene(string sceneName)
{
if(!NetworkManager.Singleton.IsHost)
return;
NetworkManager.Singleton.SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
}
According to the docs this should be enough. But after the scene is switched all clients are disconnected. What am I missing?
The scene is added to the “Scenes in build” list, the lobby itself works fine. I also tried setting “ActiveSceneSynchronizationEnabled” to true but that didn’t help.
I see you aren’t using the player prefabs. Do you “SpawnAsPlayer” objects yourself? If so, check their NetworkObject flags perhaps they are set to “destroy with owner” or something other. But this shouldn’t really affect the client.
Also check the new scene running any code that it perhaps shouldn’t, maybe some OnDisable/OnDestroy simply calls NetworkManager shutdown? You may want to set breakpoints in the NetworkManager script to see when and where and thus perhaps also why the clients disconnect.
The player objects are spawned in the game scene. They don’t exist in the lobby scene. Could this be a problem?
I only have one shutdown call in my entire code, and that’s in “LeaveLobby”. The client seemingly disconnects because the scene changes. (“Disconnect Event from 0” in console)
Not sure but worth investigating. You could temporarily spawn them in the Lobby for instance (and then don’t spawn them in the new scene).
Though this shouldn’t cause issues but since this may be an odd use case I wouldn’t rule out a bug there.
Or perhaps the player prefab spawn happens instantly after scene load on the server side, and then fails on client-side because they may not have completed the scene load. Worth delaying the player spawn on the server side until after the scene load completed (for all) event is raised, or for a quick test, delay the player spawn by a couple seconds.