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:
    6
    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:
    285
    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:
    6
    SceneManager.LoadScene can only be used in play mode so it doesn't fit my use case.
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,882
    Squirner likes this.