Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Pausing Progress Bar at Async Scene Load

Discussion in 'Editor & General Support' started by ketchupAfterDark, Dec 11, 2023.

  1. ketchupAfterDark

    ketchupAfterDark

    Joined:
    Oct 19, 2022
    Posts:
    4
    Hi!
    I have a certain scene change in a project that takes some time and so created a loading bar.
    I checked some tutorials about that and loading the scene as AsyncOperation seems to be the common practice for that, which I also discovered when browsing through forum posts about similar situations.

    Code (CSharp):
    1.     public void LevelLoadAsync(int levelNumber)
    2.     {
    3.  
    4.         StartCoroutine(LevelLoadAsyncSeq(levelNumber));
    5.     }
    6.  
    7.  
    8.     IEnumerator LevelLoadAsyncSeq(int levelNumber)
    9.     {
    10.         AsyncOperation levelLoadOperation = SceneManager.LoadSceneAsync(levelNumber);
    11.  
    12.         AccessFadeScreen.instance.ActivateProgressBar();
    13.         while (!levelLoadOperation.isDone)
    14.         {
    15.             float progressValue = Mathf.Clamp01(levelLoadOperation.progress / 0.9f);
    16.            AccessFadeScreen.instance.loadingBar.value = progressValue;
    17.  
    18.             yield return null;
    19.         }
    20.     }

    ( LevelLoadAsync function gets called at the end of the functions for new game or continue )


    So what happens is nothing serious but would be also nice to have it solved somehow.
    At around 10-20 % the progress bar pauses. At faster systems it is recognizable but seems rather normal, on slower machine it's a few seconds. And after that the bar is super quick again up to 100%.

    I'm pretty sure that this is the moment when the Awake and Start functions are loaded or maybe just from the scripts that load save files.
    And probably that's not really being counted extra in the progress?

    Could there be some other approach how the progress bar can be updated?
    Or I was also thinking about a workaround of "fake" updating the loading bar slightly during this pause,
    but I could not find any solution for that.

    Would be great if anyone had some ideas:
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,556
    Sure, you could just make up numbers all you want, and slide the "progress" bar according to a predetermined amount of time you thought would look good.

    But every platform is different. For mobile, the range between cheap older phones and this year's flagship are night and day. For PCs, the same range exists. For consoles, they're more consistent but is the data on an SD card, an external SSD drive, an internal spinning platter drive, or an internal SSD? You aren't going to predict well.

    The LoadSceneAsync does some guesswork too, and stops at an arbitrarily chosen 90% so that you can add your own post-loading OnEnable() logic that might be significantly slow to process and bog your FPS, and still count up 90~100%.

    And no players really care beyond a "huh, that's odd."
     
    Kurt-Dekker likes this.
  3. ketchupAfterDark

    ketchupAfterDark

    Joined:
    Oct 19, 2022
    Posts:
    4

    Thank you for your input!
    In the end, I left the progress bar like it was with, with this pause situation. It's only on rather slow machines where it might appear suspicious for an instant. Maybe we replace the progress bar with just a small loading animation and no progress at some point.