I’ve added a loading progress bar that is used whenever a new scene is going to be loaded in my game, but I find that after the loading bar completes there is still a fair amount (5-10seconds) of loading going on (especially on mobile). Any suggestions on how to handle that so that the progress bar is more accurate to the loading time?
I am using:
private AsyncOperation sceneLoadingOperation;
sceneLoadingOperation = Application.LoadLevelAsync(sceneName);
and getting the progress value from:
sceneLoadingOperation.progress
I don’t have Unity Pro, so I can’t test it, but looking at the scripting reference here is an idea that might work:
Let the progress bar fill for 50% using sceneLoadingOperation.progress. Then let it slowly keep filling until sceneLoadingOperation.isDone == true, then let the remaining part of the progress bar fill up.
This is of course not at all accurate, but at least you have the player watch your loading screen with a constantly filling progress bar, constantly giving the player feedback that the level is being loaded. I’d say that is more important than an accurate progress bar.
How are you updating the progress… I do it by using a IEnumerator and yeilding and it seems to work quite well, it does sometimes jump i.e 20%->60% in one frame, and the scene normally starts just before the progress bar reaches 100%…
@image28 Yes, I’m using the IEnumerator in a similar way to your code. The difference is that during this scene loading I have a tip showing up on the screen, so I have created a Start button that the player can press once the loading has completed and they have read the tip. This is because on Standalone platform the scenes often load within just a few seconds, but on mobile the load time can be 10-20 seconds, so I don’t want to just load the next scene too quickly and completely skip over the tip.
This is done using:
sceneLoadingOperation.allowSceneActivation = false;
then once the progress reaches 0.9 (it never reaches 1) then I enable the button and once the player presses the button then I set
sceneLoadingOperation.allowSceneActivation = true;
which seems to continue loading it that part still takes time, during which it seems that the screen freezes and you can’t do any other kind of animation or interaction (ie: fake the progress bar continuing or make a new progress bar).
void Update()
{
// if the scene hasn't started loading yet then skip the rest of update
if( sceneLoadingOperation == null )
return;
// check scene loading progress
if( sceneLoadingOperation.progress >= 0.9f )
{
// once at 0.9 enable the start mission button (unity doesn't seem to report past 0.9f
missionLoadingProgressBar.sliderValue = 1f;
startButton.isEnabled = true;
}
else
missionLoadingProgressBar.sliderValue = sceneLoadingOperation.progress;
}
I know, zombie thread, but for anyone coming to this thread in the future, there’s a unitycookie screencast that covers creating a loading screen on YouTube.
HTH
Thanks! I’m sure that will be helpful. I ended up using the SceneManager plugin from the asset store, but it still didn’t really cover the last 9% of the loading.