Loading Process bar

    void Start() {
        StartCoroutine(LoadNewScene());
    }

    IEnumerator LoadNewScene() {

        yield return new WaitForSeconds(timeToWait);
        AsyncOperation async = SceneManager.LoadSceneAsync(sceneNameToLoad);
        async.allowSceneActivation = false;

        while(!async.isDone) {

            fillAmount = async.progress;
           
            loadingBar.fillAmount = Mathf.Lerp(loadingBar.fillAmount, fillAmount, Time.deltaTime * 4);
       
            if(async.progress == 0.9f) {
                async.allowSceneActivation = true;
            }
           
            Debug.Log(async.progress);
            yield return null;

        }

    }

Hello,

I have problem about loading process bar for load new scene. I want to loading bar full then it get new scene.

But my code it’s loadingBar at 0.9f then it get to new scene. It not Math.Lerp 0.9 to 1.

Then make allowSceneActivation always true.

That field is there so that you can have the scene loading wait on some third party things finish loading before the scene is “allowed to activate”. Loading will always pause at 90% when allowSceneActivation is set to false. Its what the documentation says.

also using == operator on a float is subject to floating error, and likely why its still not working for you. Use “Mathf.Approximately(async.progress,0.9f)” (which interestingly enough actually has memory allocation in the profiler), or use “EqualityComparer.Default.Equals(async.progress,0.9f)”, or use “if(async.progress >= 0.9f- float.epsilon)”.

Maybe change lerp so it’s :

loadingBar.fillAmount = Mathf.Lerp(0, 1, async.progress);

Edit: Agree with @JoshuaMcKenzie , better off to switch to >= .9f

  • if(async.progress == 0.9f) {
  • async.allowSceneActivation = true;
  • }

I think this condition it’s error. Because async.progress it’s fast. And then async.allowSceneActivation = true; make to get new scene.

I want to make wait time for fill loading bar.

If you want to artificially slow it down, you could not set the allow activation to true, break out of the first loop, and do a few yields and advance the fillAmount in between. Allow the scene’s activation after some time you like. Maybe?

Can you example code for me ? Please.

You try first and show me what you come up with and we’ll work with that?