Info : Searching scenes added to build

Just off the back of a question in lastnights AMA.

To find out how many scenes have been added to the build via script.

need to use the editor SceneManagement namespace

using UnityEditor.SceneManagement;

then to get the count of the scenes in your build you can use the following that returns an INT.

EditorSceneManager.sceneCountInBuildSettings

so if the last one is always the game over you can find out what index its sitting at.

just an example script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement; // need this to the normal load scenes
using UnityEditor.SceneManagement; // need this to access the build settings as its part of the editor

public class SceneSearch : MonoBehaviour {

// Use this for initialization
void Start () {
// get the scene count that has been added to the build in File > Build Settings via script
int sceneCount = EditorSceneManager.sceneCountInBuildSettings;
Debug.Log("Scene Count in build : " + sceneCount );
}
}

2 Likes

Seemingly the new scenemanager doesnt solve finding unloaded scenes by name.

After reading this post, im wondering if its worth it.
http://davikingcode.com/blog/retrieving-the-names-of-your-scenes-at-runtime-with-unity/