EditorSceneManager Open Scene from Build Index

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?

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?

SceneManager.LoadScene can only be used in play mode so it doesn’t fit my use case.

SceneManager.GetSceneByBuildIndex

Use this instead: Unity - Scripting API: EditorBuildSettings.scenes

2 Likes