Search Unity

Loading scene progress bar

Discussion in 'Scripting' started by zedz, Oct 17, 2021.

  1. zedz

    zedz

    Joined:
    Aug 31, 2013
    Posts:
    251
    For years Ive been doing basically

    https://www.patrykgalach.com/2021/02/15/smooth-scene-loading/
    https://weeklyhow.com/loading-bar-screen-in-unity/

    this is all well and good, the bar updates usually (sometimes it just jumps straight away to 0.9)

    The problem is after it reaches 0.9 it then freezes for like 4 seconds, where nothing is done, its impossible to update the progress bar

    after these ~4 seconds the apps surrenders control to me again, so my function OnLevelFinishedLoading(..) gets called

    Could it be that my scene is a lot more complicated than the above scenes in the 2 examples, i.e. if I load a simpler scene in my game then theres not a 4 second delay its near instant.

    i.e. progress bars look good if the scene is small which begs the question, if your scene is small and loads quickly then why have a progress bar :)
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Avoid complicated code in Awake, OnEnable and Start, as all of those functions run synchronously when you load a scene.
     
    zedz likes this.
  3. zedz

    zedz

    Joined:
    Aug 31, 2013
    Posts:
    251
    OK thanks I don't think its that but I just had a quick check now just to be sure

    Sorry I had a bit of a brain fade I should include the profiler info of the frame


    you can see here it freezes for ~5 seconds
    if my scenes a bit smaller eg ~5% of the size ~20% the polygon/material etc count (i.e more dense) there is no pause i.e. the frame takes ~10msec vs nearly 500x slower here, sure its larger but no where near 500x larger