1
votes

I use the function Application.LoadLevelAsync (s); in my game but it just stops at 89%. Help me. It's my code:

public void LoadScenes (string s)
{
    if (!quit) {
        SoundController.PlaySound (soundGame.ButtomClick);
        progressBars.gameObject.SetActive (true);
        background.SetActive (true);
        text.gameObject.SetActive (true);
        async = Application.LoadLevelAsync (s); 
        async.allowSceneActivation = false;
        StartCoroutine (DisplayLoadingScreen ());
    }
}
IEnumerator DisplayLoadingScreen ()
{
    while (!async.isDone) {
        loadProgress = (int)(async.progress * 100);
        text.text = "Loading Progress " + loadProgress + "%";
        progressBars.size = loadProgress;
        yield return null;
    }
    if (async.isDone) {
        Debug.Log ("Loading complete");
        async.allowSceneActivation = true;
    }
}
2

2 Answers

0
votes

When you set async.allowSceneActivation = false, the loading stops at 90% or 0.9. This is because unity saves the last 10% to actually show you the scene that has been loaded. So 0 to 0.9 is when the actual loading process takes place and the last .1% is for displaying the loaded scene.

So in your case, you are checking for async.isDone which would become true only when progress is 100% but you have also set async.allowSceneActivation = false which would stop the progress at 90%. What you might want to check is async.progress >=0.9f and then set your async.allowSceneActivation = true.

Reference: https://docs.unity3d.com/ScriptReference/AsyncOperation-progress.html

-1
votes

From my experience, AsyncOperation.progress can cap out at about 89% as you've discovered. It may look like it's stalled at that message, when really it's still loading for however long it needs. It won't ever reach 100% even when it's done though, so it's rather useless if you want to implement a loading bar.

As such, async.isDone might never become true.

As a workaround, you could set async.allowSceneActivation = true; sooner than later, ignoring async.progress altogether:

async = Application.LoadLevelAsync (s); 
async.allowSceneActivation = true;

I tend to use a progress-agnostic rotating loading icon instead of a loading bar because of this issue.


On a side note that I haven't tested, others have said that this is an Editor-only issue; async.progress and async.isDone might actually work on standalone builds.