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.

@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.

Just spent about 30 minutes on this. Looked trivial but it’s not apparently. The name of this method is terribly misleading. Thanks

I can’t get it to work any way I’ve tried

Method name is very misleading and method function is very confusing. You can use SceneManager.sceneCount and SceneManager.GetSceneAt to loop through the loaded scenes. This will help to check whether scene is loaded or not irrespective of active scene.