Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how exactly does the Scene Manager work?

Discussion in 'Scripting' started by Miziziziz, Jan 17, 2016.

  1. Miziziziz

    Miziziziz

    Joined:
    Jun 25, 2013
    Posts:
    73
    Been running into a lot of issues with the new Scene Manager lately and have a lot of questions, since there's almost nothing on it in the docs.

    Basically, I have a script I use in the editor to generate a level select screen (basically a ton of grid elements that I can click on to load a level).

    Here's some examples of things I don't understand:
    SceneManager.sceneCount returns 1 (which is not correct, I have many more scenes than that) (also, pretty sure this just started happening recently, I've never checked what it returns before),while
    SceneManager.sceneCountInBuildSettings returns 51 (which is correct, that's the number of scenes I have in the build settings)

    Just recently, SceneManager.GetSceneAt(index) has started throwing null exception errors whenever I use it for anything higher than 0, even though it's always worked before.Before, I had assumed it meant it got the scene at that index in the build settings, but now I see it goes by sceneCount instead of sceneCountInBuildSettings.
    Is there a way to GetSceneInBuild or something?

    How do I add scenes to the scene manager? SceneManager.GetSceneAt() has the description text of "Get the scene at index in the SceneManager's list of added scenes." But I've found no way to modify whats been added to this list. Or even see this list.
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    I'm not sure how it has worked before the current version, but a little testing shows that this is the number of scenes currently loaded. The documentation is terribly vague. And terrible. The only way I've managed to get this higher than 1 is through additive loading.

    SceneManager.sceneCountInBuildSettings would be unnecessary if sceneCount returned the same number though ;)
     
  3. Miziziziz

    Miziziziz

    Joined:
    Jun 25, 2013
    Posts:
    73
    hmm, I just figured it would return the number of all scenes in your project, whether or not they were in the build.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Scenes in your project but not in the build have never been accessible for loading, even before SceneManager was a thing.
     
  5. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    SceneManager is not an editor-specific thing. During runtime it wouldn't be able to report scenes not in the build, because those don't exist ;)