Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Cannot load scene via SceneManager

Discussion in 'Editor & General Support' started by AntJack, Dec 1, 2018.

  1. AntJack

    AntJack

    Joined:
    Oct 9, 2018
    Posts:
    4
    Hello,

    I tried to load scene using the scenemanager in Unity, but I can't seem to be able to get it to load the next scene, either by name or by index.

    Here is my build index:
    buildIndex.PNG

    And what visual studio shows when I try to load the next scene:

    sceneLoadingErrors.PNG

    I have seen many posts and have tried to build with all the scenes, without any of them and then building with them again. For some reason, the counts between the scenemanager and the build settings is different.

    Can anyone help me?
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,634
  3. AntJack

    AntJack

    Joined:
    Oct 9, 2018
    Posts:
    4
    ok then, If that is not the problem what could be the cause for it to not be able to load "Lvl2"?
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,634
    post your code in code tags here, we wouldn't know otherwise, how do you load it?
     
  5. AntJack

    AntJack

    Joined:
    Oct 9, 2018
    Posts:
    4
    Here is the code I use:


    Code (CSharp):
    1.  
    2. void transitionToNextLevel()
    3.     {
    4.         if (levelPassed)
    5.         {
    6.             /** /
    7.             string nextSceneName = lvlPrefix + SceneManager.GetActiveScene().buildIndex + 1;
    8.             if (SceneManager.GetSceneByName(nextSceneName).IsValid())
    9.             {
    10.  
    11.                 SceneManager.LoadScene(nextSceneName);
    12.                 return;
    13.             }
    14.             /**/
    15.             int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
    16.             if (SceneManager.GetSceneByBuildIndex(nextSceneIndex).IsValid())
    17.             {
    18.  
    19.                 SceneManager.LoadScene(nextSceneIndex);
    20.                 return;
    21.             }
    22.         }
    23.      
    24.         //either game passed or lost level
    25.         SceneManager.LoadScene(0);
    26.      
    27.  
    28.     }
    29.  
    Either one of the codes doesn't work.
     
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,634
    AntJack likes this.
  7. AntJack

    AntJack

    Joined:
    Oct 9, 2018
    Posts:
    4
    Lurking-Ninja likes this.