Application.loadedLevel - Obsolete

Where?

It was that: restart the scen:

private IEnumerator ReloadLevel(Entry entry)
        {
            yield return new WaitForSeconds(entry.delay);
            SceneManager.LoadScene(Application.loadedLevel, false);
        }

The problem is that Application.loadedLevel doesn’t really make sense in a situation where you can have multiple levels loaded at the same time.

If you know that you only have one level loaded, you can use GetSceneAt to access it like this:

private Enumerator ReloadLevel(Entry entry)
{
    yield return new WaitForSeconds(entry.delay);
    SceneManager.LoadScene (SceneManager.GetSceneAt(0).buildIndex, false);
}
1 Like