Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Scenes with netcode in single mode are not reloaded on late connected clients

Discussion in 'Multiplayer' started by Mauschelbaer, Jan 22, 2023.

  1. Mauschelbaer


    Aug 4, 2019
    I'm trying to build up the basic functionality of a multiplayer game with netcode.
    However, I still have problems with netcode and understand it properly.

    I would like to go directly "in-game" as a host and if a client joins/connects later,
    should this also come directly in-game.

    Since Netcode takes over the scene management for me, this should be possible via
    . Here is a minimal example:

    Code (CSharp):
    2.     public void StartGameAsHost(string profileId)
    3.     {
    4.         NetworkManager.Singleton.StartHost();
    6.         if (IsServer)
    7.         {
    8.             NetworkManager.SceneManager.LoadScene("TestMap01", LoadSceneMode.Additive);
    9.         }
    11.     }
    13.     public void JoinGameAsClient(string profileId)
    14.     {
    15.         NetworkManager.Singleton.StartClient();
    16.     }
    That works. But only as long as I selected LoadSceneMode.Additive. The client then builds exactly the same scenes. However, if I switch to LoadSceneMode.Single, nothing seems to change on the client after the connect, i.e. no scene is loaded.

    My second problem is that I would like to load multiple Additive Scenes, but unlike the local one, I can only load one at a time. Is it not possible to load multiple complementary scenes via network?

    Code (CSharp):
    2.     NetworkManager.SceneManager.LoadScene("TestMap01", LoadSceneMode.Additive);
    3.     NetworkManager.SceneManager.LoadScene("Gameplay", LoadSceneMode.Additive);
    What can be the reason? Maybe someone can help me?
  2. Mauschelbaer


    Aug 4, 2019
    Okay, I found out that using single does work. Nothing was displayed visibly, because the complete replacement of a scene logically deletes all non-DDoL GameObjects on both the server and client side, which in my case meant that there was no camera in the new scene.:confused:

    However, my second problem with the multiple additive scenes remains
  3. CodeSmile


    Apr 10, 2014
    Generally speaking it is best to not do anything straight after calling StartHost/Server but rather delay anything (ie load scene) to the usual callback event such as client connected or OnNetworkSpawn.

    Similarly I can imagine (just a hunch) that you cannot issue multiple additive scene loads right after another. Instead wait for the „scene was loaded“ callback and then load another scene additively.
    Mauschelbaer likes this.