Search Unity

  1. How has 2019.2 and the beta been for you so far? Give us feedback in this thread.
    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

    Quis aedificabit ipsos aedificatores? Unity Technologies

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