Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Need Clarification how LoadScene affects NetworkManager

Discussion in 'Netcode for GameObjects' started by Alex_2022, Aug 30, 2022.

  1. Alex_2022

    Alex_2022

    Joined:
    May 4, 2022
    Posts:
    16
    There is a MainMenu. When you press a button "New Game", a script will invoke

    Code (CSharp):
    1. NetworkManager.Singleton.StartHost();
    2. [...]
    3. SceneManager.LoadScene("CampaignScene");
    The host is started successfully.

    In the CampaignScene, there is a CampaignManager-Object which is In-Scene placed. The CampaignManager has a component NetworkObject and a script of type NetworkBehaviour assigned to it. However, after the Scene is loaded, the CampaignManager is not spawned. The Start()-method is called, and Debug.Log(IsHost) shows that the host is NOT started. But the inspector clearly shows that the host is started and i could call
    Code (CSharp):
    1. void Start() {
    2.     GetComponent<NetworkObject>().Spawn();
    3. }
    which would work on the host-side, but later on turns into problems with the client side...

    I am lost here. Why is the CampaignManager not spawned? And why does it say IsHost == false??
    Is this a bug or does it work as designed?
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    700
    It sounds like you need to be calling the NetworkManager's scene manager, try:
    Code (CSharp):
    1. NetworkManager.Singleton.SceneManager.LoadScene("CampaignScene", LoadSceneMode.Single);
     
    CreativeChris and Alex_2022 like this.
  3. Alex_2022

    Alex_2022

    Joined:
    May 4, 2022
    Posts:
    16
    Thank you very much for your quick reply. That did the job. :)

    I have read the whole multiplayer-documentation but somehow missed the part about the SceneManagement :(
     
    CreativeChris and cerestorm like this.