Search Unity

EditorSceneManager Open Scene from Build Index

Discussion in 'Scripting' started by liphttam1, Oct 11, 2018.

  1. liphttam1

    liphttam1

    Joined:
    Nov 11, 2014
    Posts:
    9
    Hey all,

    I'm trying to use EditorSceneManager.OpenScene but I want to use build index to determine the scene I open.

    I wanted to use EditorSceneManager.OpenScene(EditorSceneManager.GetSceneByBuildIndex(0).path) but this will return null, (I do have scenes in my build index btw)

    Is there any way I can use EditorSceneManager.OpenScene with build index?
     
  2. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    I'm a bit confused to why you're going through all that work when you can simply do SceneManager.LoadScene(0); replacing 0 with the scene build index.
    Or if it is an editor mode scene, do EditorSceneManager.LoadScene(0);

    Is that not what you want to do?
     
  3. liphttam1

    liphttam1

    Joined:
    Nov 11, 2014
    Posts:
    9
    SceneManager.LoadScene can only be used in play mode so it doesn't fit my use case.
     
  4. lazyrays and Squirner like this.