Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Progress always at 0

Discussion in 'Scripting' started by LazyGhost15, Mar 14, 2023.

  1. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120
    I used the "SceneManager.LoadSceneAsync" function and then asked the console to print the progress but it always return 0 even though the scene loaded. Idk if my code is wrong I watched several tutorials before:
    Code (CSharp):
    1. IEnumerator ProgressBar(int SceneIndx)
    2.     {
    3.         AsyncOperation op = SceneManager.LoadSceneAsync(SceneIndx);
    4.  
    5.         while (!op.isDone)
    6.         {
    7.             float progress = Mathf.Clamp01(op.progress / .9f);
    8.             Debug.Log(op.progress);
    9.  
    10.             yield return null;
    11.         }
    12.  
    13.     }
     
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Code (CSharp):
    1. IEnumerator ProgressBar(int SceneIndx)
    2.     {
    3.         AsyncOperation op = SceneManager.LoadSceneAsync(SceneIndx);
    4. op.allowSceneActivation = false;
    5.  
    6.         while (!op.isDone)
    7.         {
    8.             float progress = Mathf.Clamp01(op.progress / .9f);
    9.             Debug.Log(op.progress);
    10.  
    11.             if(progress >= 0.9f)
    12.             {
    13.                op.allowSceneActivation = true;
    14.                  yield return new WaitForSeconds(1);
    15.             }
    16.             yield return null;
    17.         }
    18.     }
    Try that, i feel like all you are missing is the allowSceneActivation. Without it, theres a good chance you see nothing happen at all, especially on fast loading content.
     
  3. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    120


    Nope, It still reporting 0 twice, I guess because the scene is loaded so fast it reports once the operation starts and once when it ends, but both of the reports are still 0
     
  4. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Hmm, possibly i forgot something, but you should have definitely noticed a 1 second pause.

    I currently have a loader working on screen right now, with exactly the same implementation.

    If you dont mind a screenshare, hit me up on discord. JD#1539.

    Im sure its something silly. This same issue has popped a few times in jsut the past few days on these forums.
     
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,610
    I think what you're seeing is just that scene-loading works a bit differently in the Editor.

    Build your project out, see if you see the same results.