c# – Getting the index of the active scene in Unity


Good evening!

It is necessary to put the index of the active scene in the variable i .
The next code variant throws an error.

using ...
using UnityEngine.SceneManagement;

byte i;
i = (byte)(SceneManager.sceneLoaded());

How to correctly implement the task (using SceneManager)?


You need this:


Because GetActiveScene() returns the currently active Scene object, then it contains the very cherished index – Scene.buildIndex . And name too, if you suddenly need it.

Scroll to Top