fidgetik
fidgetik

Reputation: 7

Cant load EasyAr scene by LoadSceneAsync

I trying to load scene with EasyAR asynchronously by script b. But its doesnt work.

SceneManager.LoadSceneAsync("Scene_name")

It works if I try to load scene using

SceneManager.LoadScene("Scene_name")

The question is: Is there any way to load it async?

Working with c#.
Test on Android device.
Unity 2018.3.12f
Easy AR ver. 3.0


Thanks!

New code update:

  private void WallSceneLoader()
    {
        _loaderGameObject.SetActive(true);
        var asyncScene = SceneManager.LoadSceneAsync(Constants.Scenes.AR_SCENE);
        asyncScene.allowSceneActivation = false;

        while (asyncScene.progress < 0.9f)
        {
            var progress = Mathf.Clamp01(asyncScene.progress / 0.9f);
            _loaderBar.value = progress;
        }

        Debug.Log("asyncScene.isDone = true");
        asyncScene.allowSceneActivation = true;}

The _loader.gameObject its just slider with progression bar.

Upvotes: 0

Views: 433

Answers (1)

derHugo
derHugo

Reputation: 90739

By using this while loop in a "normal" method you block the thread anyway so you loose the entire advantage of async here.


What you rather want to do is use it in a Coroutine like it is actually also shown in the example for SceneManager.LoadSceneAsync

private IEnumerator WallSceneLoader()
{
    _loaderGameObject.SetActive(true);
    var asyncScene = SceneManager.LoadSceneAsync(Constants.Scenes.AR_SCENE);
    asyncScene.allowSceneActivation = false;

    while (asyncScene.progress < 0.9f)
    {
        var progress = Mathf.Clamp01(asyncScene.progress / 0.9f);
        _loaderBar.value = progress;

        // tells Unity to pause the routine here
        // render the frame and continue from here in the next frame
        yield return null;
    }

    Debug.Log("asyncScene.isDone = true");
    asyncScene.allowSceneActivation = true;
}

And then use StartCoroutine where you want to call it

StartCoroutine(WalSceneLoader());

Upvotes: 1

Related Questions