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

Get built-in scene name at runtime?

Discussion in 'Getting Started' started by skyfancy, Dec 10, 2020.

  1. skyfancy

    skyfancy

    Joined:
    Jan 25, 2014
    Posts:
    4
    Hi there,
    How could I get all the built-in scene names at runtime? I only found EditorBuildSettings.scenes
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I haven't needed to do this, but if you get a reference to the scene it looks like you can access its name there, without needing the UnityEditor namespace.

    https://docs.unity3d.com/ScriptReference/SceneManagement.Scene.html

    You can get reference to a scene probably several ways, but one way is to ask for it by index number.

    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetSceneByBuildIndex.html

    If you need to look at all the scenes, you should be able to use the count of scenes to figure out what are valid index numbers. You should then be able to iterate through all scene references by grabbing them one by one with all valid scene indexes.

    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneCountInBuildSettings.html

    Again, I've never needed to do this. Just doing a little RTFM for you cause I found the question interesting. There may also be a more direct and simpler way.
     
    Propagant likes this.
  3. skyfancy

    skyfancy

    Joined:
    Jan 25, 2014
    Posts:
    4
    I was thinking there might be a direct way to do this, because Unity has it referenced in build setting. But now i already changed my way of doing things, still thanks for the RTFM work.
     
    Joe-Censored likes this.