Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Application.loadedLevel - Obsolete

Discussion in '5.3 Beta' started by DxStd_IgnatPribylov, Oct 11, 2015.

  1. DxStd_IgnatPribylov

    DxStd_IgnatPribylov

    Joined:
    Sep 24, 2015
    Posts:
    30
    Where?
    It was that: restart the scen:
    Code (CSharp):
    1. private IEnumerator ReloadLevel(Entry entry)
    2.         {
    3.             yield return new WaitForSeconds(entry.delay);
    4.             SceneManager.LoadScene(Application.loadedLevel, false);
    5.         }
     
    Last edited: Oct 11, 2015
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    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:

    Code (csharp):
    1.  
    2. private Enumerator ReloadLevel(Entry entry)
    3. {
    4.     yield return new WaitForSeconds(entry.delay);
    5.     SceneManager.LoadScene (SceneManager.GetSceneAt(0).buildIndex, false);
    6. }
    7.  
     
    LaurieAnnis likes this.