Getting list of all opened scenes

Hi, I can see there is EditorSceneManager.loadedSceneCount, but I can’t find function that returns all opened scenes, anyone knows if there is such function at all?

Nevermind, SceneManager.GetAllScenes returns all loaded scenes, it’s just not documented.

4 Likes

In case anyone runs into this as I did, here’s the new way:

        int countLoaded = SceneManager.sceneCount;
        Scene[] loadedScenes = new Scene[countLoaded];

        for (int i = 0; i < countLoaded; i++)
        {
            loadedScenes[i] = SceneManager.GetSceneAt(i);
        }
18 Likes

Note: SceneManager.GetAllScenes() is deprecated (not sure if it was in Feb 2016) and the suggested new solution is above.

1 Like

Why the heck was it deprecated? Everybody’s just going to add their own GetOpenScenes() method using the above method…

9 Likes

Too true

2 Likes

Definitely true.

2 Likes

Unity being unity

3 Likes

It was probably deprecated because it allocates an array. Unity is generally moving away from any API call that allocates so that devs can manage and avoid needless allocations and GC. At least with the custom class, you can manage the memory and cache the scene list to avoid unnecessary allocations.

10 Likes