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. Dismiss Notice

Question Load client to the same scene as the host

Discussion in 'Relay' started by internet_maze, Jan 6, 2023.

  1. internet_maze

    internet_maze

    Joined:
    Oct 29, 2022
    Posts:
    1
    I have a client that connects to the host using the code provided to the host when they create a relay.
    The connection works fine, but the client does not load the same scene as the host.
    I've already tried using the network scene manager

    Code (CSharp):
    1. public class NetworkSceneChange : NetworkBehaviour
    2. {
    3.     [SerializeField] private string sceneName;
    4.     [SerializeField] private Button sceneChangeBtn;
    5.  
    6.     public override void OnNetworkSpawn()
    7.     {
    8.    
    9.         sceneChangeBtn.onClick.AddListener(() =>
    10.         {
    11.             NetworkManager.SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
    12.         });
    13.        
    14.     }
    15.  
    16. }
    However, the host does not load into the scene for some reason. Only loads in when I use a normal scene manager.
    Basically, I need the host to load a scene and for the client to load on the same scene after connecting.
     
  2. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    48
    @internet_maze
    I think I can help you with this.
    The first thing to check is your project's Build Settings-->Scenes in Build list.
    upload_2023-1-6_9-43-16.png
    Any scene you want to be able to synchronize between the host/server and clients when using the NetworkSceneManager needs to be in this list.

    There are two ways scenes will get synchronized with clients:
    1. Scenes already loaded by the server prior to starting NetworkManager
      1. Scenes loaded on the server side before the sever is started will be automatically synchronized with clients when they first connect. You can use the normal Unity SceneManager for this, but you need to make sure they are loaded prior to starting the server.
    2. Scenes loaded after the NetworkManager has been started.
      1. Once the server has started, you should always use the NetworkManager.SceneManager (NetworkSceneManager). You can subscribe to NetworkManager.OnServerStarted to know when it is safe for a server to load a scene via NetworkManager.SceneManager.
      2. Scenes loaded via the NetworkSceneManager (NetworkManager.SceneManager) will automatically get loaded on already connected clients and will be loaded by clients that connect after the scene(s) has/have been loaded (i.e. late joining clients).
    I would also highly recommend reading over the the NGO Integrated Scene Management sections starting with:
    Using NetworkSceneManager | Unity Multiplayer Networking (unity3d.com)

    Additionally, here are two places you can find scene loading examples:
    The NGO TestProject contains some scene loading examples that might be useful to look through as well.

    NGO Bootstrap Usage Pattern
    If you want to start with an "all in one" project that uses an NGO bootstrap usage pattern, you can look at a small "quick start" project of mine (link above) that has a detailed walk through of the components in the project and gets you up and running with an already existing framework that you can expand upon.

    If none of the above helps and you are still running into issues, then if you could you provide me with:
    • The version of Netcode for GameObjects you are using
    • The version of Unity you are using
    • More details of the sequence of events (or a repository link would be the fastest way)
    I will better be able to help you troubleshoot.
     
  3. zyleo

    zyleo

    Joined:
    Apr 14, 2023
    Posts:
    1
    Awesome answer, thanks a lot.