Use of SceneManager.MoveGameObjectToScene?


I am trying to move my player/gameobject to the next scene being loaded.

 public void loadLevelasync(int id, GameObject player)
        StartCoroutine(fadeIn(loadingCanvas, 2.0f));

        Scene nextLevel = SceneManager.GetSceneAt(id);
        SceneManager.MoveGameObjectToScene(player, nextLevel);
    IEnumerator loadScene(int id)
        AsyncOperation async = SceneManager.LoadSceneAsync(id);
        while (!async.isDone)
            loadingBar.value = async.progress / 0.9f;
            yield return null;

I can load the scene async perfectly, but my gameobject is not in the next loaded scene hierarchy and the lighting is not fully done.

How exactly does MoveGameObjectToScene work?


@sk8terboy4 Instead of using SceneManager.MoveGameObjectToScene(player, nextLevel), you can simply use:

Object.DontDestroyOnLoad(player.gameObject); //You might be able to just use 'player'.

Or if the script you are on is the player’s script, you can simply use:

Object.DontDestroyOnLoad(this.gameObject); //You might be able to just use 'this'

Sorry about the long time waiting, I have only come across this problem today.

This is how to keep objects (different than moving objects from scene to scene however it might help you)… Unity - Moving Objects Between Scenes - YouTube