How can a client change their scene when joining mid game?

I have two scenes, let’s call them StartGameScene and GameScene. StartGameScene has 2 buttons, one to Start a host and one to join a game (using a join code).

If I spin up an instance of the game and click to Start a host, the NetworkSceneManager is called to switch the host to the GameScene. This works fine and my player prefab is spawned correctly along with any network objects that I’ve spawned.

If I then use a different instance of the game to join the in progress game using the join code, how can I have that client switch to the GameScene?

I tried calling NetworkSceneManager using the client but I’m met with an error that only the server can use that (I understand why). If I use the regular SceneManager to switch to the GameScene on the client, I don’t have any of the network objects spawned and it’s as if I just loaded this scene without any network support.

Can someone please clarify how to go about doing this? Am I supposed to use the host to listen for the client connect and request a scene change there? Documentation around this is lacking unfortunately.

Upon calling NetworkManager.Singleton.StartClient(), the client should automatically be switched to the scene of the host, assuming the host loaded it through the NetworkManager too (NetworkManager.Singleton.SceneManager.LoadScene(...)).

In order for the auto sync of scenes to happen, you need to make sure that the NetworkManager’s “Enable Scene Management” bool is set to true in the inspector as well :slight_smile:

Hi, I tried to do it this way, but after I click the host button (that firstly runs this code NetworkManager.Singleton.StartHost()) I want to load the next scene by using that code you showed. I previously stored the scene as gameScene = SceneManager.GetSceneByBuildIndex(1);, and I’m trying this piece of code:
NetworkManager.Singleton.SceneManager.LoadScene(gameScene.name, LoadSceneMode.Single);
however, I’m getting the following error

The scene is in build list. In fact, I can load the scene pretty easily by using SceneManager. Notwithstanding, I want the scenes to be synchronized with other clients, and that’s why I’m trying to get this method done. Any idea of what could be causing this issue?

That’s very strange, you’re calling the network scene manager correctly… If the scene is really in the build list then the only thing I can think of is that you’re maybe calling LoadScene slightly too fast. What I do myself is subscribe to OnServerStarted and call the scene loader from there:

void Start() {
    NetworkManager.Singleton.OnServerStarted+=HandleServerStarted;
} //Start

private void HandleServerStarted() {
    NetworkManager.Singleton.SceneManager.LoadScene(sceneName,LoadSceneMode.Single);
} //HandleServerStarted

Thanks for the reply. I found what the issue was and I explained on this thread how I fixed it.

Apparently, the scene name was null because this code: gameScene = SceneManager.GetSceneByBuildIndex(1); does not retrieve the data correctly.

gameScenePath = SceneUtility.GetScenePathByBuildIndex(1);
string gameSceneName = System.IO.Path.GetFileNameWithoutExtension(gameScenePath);

on the other hand did the trick.

Appart from that, I want to ask something out of curiosity:

I tried loading the scene with the SceneManager and also with the NetworkManager, but I don’t see any difference, they look the same to me. Why is it recommended to do it with the NetworkManager?