- Home /
SceneManager.GetSceneByName Does Not Work Even After Building
int sceneIndex = SceneManager.GetSceneByName("Scenes/Scene2").buildIndex;
SceneManager.LoadScene(sceneIndex);
This is my current script. After I ran this script, the console said: Scene '' (-1) couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
Then go to File -> Build Settings... and added Scenes/Scene1 and Scenes/Scene2, and chose build and run. However, I received the same err message. How can I load other scenes? I'm using Unity 5.3 on Mac OS X El Capitan.
Answer by BobbyDoogle · Sep 21, 2016 at 05:03 PM
@concert0 I just did some testing with this. GetSceneByName only appears to return scenes that are currently loaded/active, regardless of if they are added in your build settings. I have a game with a ton of added scenes, and this for instance, only outputs the one currently loaded scene:
int count = SceneManager.sceneCount;
for (int i = 0; i < count; i++) {
Scene s = SceneManager.GetSceneAt(count-1);
Debug.Log(s.name);
}
What exactly are you looking to do with the "Scene" you are identifying, you can do this:
SceneManager.LoadScene("somescene");
I too am finding the scene manager unnecessarily pain to deal with.
Answer by Magnesium · Apr 14, 2021 at 01:08 PM
Just spent about 30 minutes on this. Looked trivial but it's not apparently. The name of this method is terribly misleading. Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612084930im_/https://answers.unity.com/themes/thub/images/avi.jpg)