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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Scene Switching with Multiplayer Networking

Discussion in 'Multiplayer' started by avi12345, Mar 26, 2018.

  1. avi12345

    avi12345

    Joined:
    Mar 21, 2018
    Posts:
    4
    I have two entirely different minigames, and I want to switch to the second game after the players has finished the first. Additionally, there is a networking component for both, with each part having its own unique NetworkManager.

    How can I go about doing this? SceneManager.LoadScene does not seem to be enough, as the network seems to stay with the first NetworkManager.

    Edit: From reading more, it seems like I should not have more than one NetworkManager. Is that correct?
     
    Last edited: Mar 26, 2018
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Hi Avi, yeah the best bet would be to have one single network manager for your game. It becomes a singleton and stays throughout the whole playthrough of your game.

    A good bet is to take a look through https://docs.unity3d.com/ScriptReference/Networking.NetworkManager.html. Specifically there's a method called 'ServerChangeScene(string newSceneName) (https://docs.unity3d.com/ScriptReference/Networking.NetworkManager.ServerChangeScene.html). That is what you want to do when you want them to go to a new scene.

    Another good port of call is to make sure the 'Player' the NetworkManager is spawning is just an empty GameObject with a PlayerConnection class, or something similar. From there, you can listen to SceneManager.activeSceneChange events and instantiate the PlayerConnection's physical player, and then spawn it on the server.

    Does that make sense?
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  4. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129