Clients get disconnected on scene change [Solved]

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.

Log from the client:

What about the host side? Any errors there?

No errors on the host. The host switches the scene successfully.

Also, I forgot to mention: both the NetworkManager game object and my LobbyManager are “DontDestroyOnLoad”.

To add some more context, this is how I create and join lobbies:

public async Task<Lobby?> CreateLobby()
{
	currentLobby = await SteamMatchmaking.CreateLobbyAsync(4);

	if(currentLobby.HasValue)
	{
		currentLobby.Value.SetFriendsOnly();
		currentLobby.Value.SetJoinable(true);

		NetworkManager.Singleton.SceneManager.ActiveSceneSynchronizationEnabled = true;
		NetworkManager.Singleton.StartHost();
	}

	return currentLobby;
}

public async Task<Lobby?> JoinLobby(ulong lobbyId)
{
	currentLobby = await SteamMatchmaking.JoinLobbyAsync(lobbyId);

	if(currentLobby.HasValue && !NetworkManager.Singleton.IsHost)
	{
		NetworkManager.Singleton.GetComponent<FacepunchTransport>().targetSteamId = lobbyId;
		NetworkManager.Singleton.StartClient();
	}

	return currentLobby;
}

And my NetworkManager settings:

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.

Adding a delay did not help either.

But setting a breakpoint revealed that the “SteamClient.RunCallbacks()” ultimately calls the Shutdown:

So I guess this a problem with the FacepunchTransport and/ or Steamworks?

Found the problem. I set the “targetSteamId” to the lobby ID instead of the owner ID.

Before:

NetworkManager.Singleton.GetComponent<FacepunchTransport>().targetSteamId = lobbyId;

After:

NetworkManager.Singleton.GetComponent<FacepunchTransport>().targetSteamId = currentLobby.Value.Owner.Id;
1 Like