Search Unity

Network Lobby Manager wait for load scene

Discussion in 'Scripting' started by Gogin, Oct 20, 2018.

  1. Gogin


    Nov 9, 2013
    Hey all,

    I work on network TD game and I was trying use "Network Lobby Manager" script from Unity. I have player prefab where is attached Player script which use Start/Awake function for finding Controler of game

    Code (CSharp):
    1.         controler = GameObject.FindGameObjectWithTag("Controler").GetComponent<Controler>(); //get controler of game
    It is fine until I used this script where I setup Lobby scene and In Game Scene - this function return null and everything goes into error. I guess there is the issue with wait until scene is loaded (prefab is spawned before scene is load and there is null on FindGameObjectWithTag)

    I was searching how to "wait" until scene is load something like below but I am not sure how to use it (need run it once like start/awake function):

    Code (CSharp):
    1.     void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    2.     {
    3.         Debug.Log("OnSceneLoaded: " +;
    4.         Debug.Log(mode);
    6.         SetupStartup();
    7.     }
    9.     // called first
    10.     void OnEnable()
    11.     {
    12.         Debug.Log("OnEnable called");
    13.         SceneManager.sceneLoaded += OnSceneLoaded;
    14.     }
    16.     // called when the game is terminated
    17.     void OnDisable()
    18.     {
    19.         Debug.Log("OnDisable");
    20.         SceneManager.sceneLoaded -= OnSceneLoaded;
    21.     }