Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How to load networked scene in client side

Discussion in 'Netcode for GameObjects' started by bluepilkintonching, Jan 17, 2023.

  1. bluepilkintonching

    bluepilkintonching

    Joined:
    Nov 29, 2019
    Posts:
    30
    Hi there!
    Can someone please explain to me in simple terms how to load a networked scene for the clients? Currently, on the server side, I am running:

    Code (CSharp):
    1. NetworkManager.Singleton.SceneManager.LoadScene("Town", UnityEngine.SceneManagement.LoadSceneMode.Single);
    But this piece of code does not work on the client side. I feel like I've read the docs 5 times but I still don't quite understand how I am supposed to approach loading a scene on the clients and have everything synced up properly.

    Thanks!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,508
    There is no scene loading on the client side. If the client isn't automatically loading the scene the server has currently loaded, there's some issue with that in your code / project / build.

    For example if you call StartHost() and immediately call LoadScene() on the server (rather than in OnNetworkSpawn for example) this may cause issues if I interpret a recent forum post about scene loading correctly. Or attempting to load scenes on the client side. Or server/client builds differ (hint: use Multiplay package or ParrelSync).

    In any case, if the server loads a scene, all clients will load that scene too. If a client joins the game late, then that client will load the server's current scene. If you merely want a client to tell the server to change scenes, then call a ServerRPC method from the client and let the server change the scene.
     
  3. bluepilkintonching

    bluepilkintonching

    Joined:
    Nov 29, 2019
    Posts:
    30
    Hey! Thanks for getting back to me, that clears up a lot about scene management with netcode! You were right about it being an issue with my code, I had forgotten to set the host relay data. o_O

    Thanks again!