Search Unity

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:
    665
    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.