SceneManager.GetAllScenes() only returns the current scene

I’ve got a project where I simply want to put a scene menu. Here’s the code:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class PickScene : MonoBehaviour {
    Scene[] Scenes;
	// Use this for initialization
	void Start () {
        Scenes = SceneManager.GetAllScenes();
	// Update is called once per frame
	void Update () {


    void OnGUI()
        for (int i = 0; i < Scenes.Length; i++)
            if (GUI.Button(new Rect(10, i*50,300,45), Scenes*.name))*

Works as expected, with no errors, but it only puts up a button for the Current scene, the Menu. There are two other scenes in the Build Settings, but they don’t show up, so I can’t test if this is working. The Debug shows 1 Scene. Any idea why this wouldn’t show me how many scenes there are?
** The documentation on this is not complete, so I have nowhere else to turn.

Until they give us a GetScenesInBuildSettings(), you can get a list of build settings scenes using EditorBuildSettings.scenes

The catch is it’s UnityEditor only. But you can create a custom inspector that saves it to a list in some Monobehaviour.

They are ordered, so remove the non-enabled scenes and you can get the buildIndex.
To get the scene name, use Path.GetFileNameWithoutExtension(scenePathFromBuildSettings);

I had the same problem and with the help of this post I could fix it.
I think this code could help those who want to solve the same problem.

Thanks! :slight_smile:

using UnityEditor;
using System.IO;

	EditorBuildSettingsScene[] allScenes = EditorBuildSettings.scenes;
	Debug.Log ("All Scenes : Length : "+allScenes.Length);
	string path;
	for (int i = 0; i < allScenes.Length; i++) {
		Debug.Log ("All Path : Scene : "+allScenes*.path);*

_ path = Path.GetFileNameWithoutExtension (allScenes*.path);_
Debug.Log ("Clear Path : Scene : "+path);_

The confusing thing is, there is a EditorSceneManager and a SceneManager. The SceneManager works also in the Editor as well.

This example fills a scenes array with all scenes in the hierarchy.

using UnityEngine.SceneManagement;    
Scene[] Scenes = new Scene[SceneManager.sceneCount];
    for (int i = 0; i < SceneManager.sceneCount; i++) {
    	Scenes *= SceneManager.GetSceneAt(i);*

_ Debug.Log(Scenes*.name);_