Proper way to use loadsceneaync and allowSceneActivation in Unity 5.6.1f1 on Windows?

Hi all,

I need to reload current scene and just like what I’ve done, I created coroutine like this:

First: Start the coroutine:

StartCoroutine(LoadNewScene(SceneManager.GetActiveScene().buildIndex));

Second, create the LoadNewScene function:

IEnumerator LoadNewScene(int no)
{
async = SceneManager.LoadSceneAsync(no);
async.allowSceneActivation = true;
while (!async.isDone)
{
yield return null;
}
}

but, it still stops at 90%. What surprised me was that the code above worked in other scenes, where it is required to load another scene even without the allowSceneActivation statement.

Do you mind shedding some light on what the proper way of using them is?

Thanks a lot!

Are you starting the coroutine in Awake? Apparently if you start the load from Awake the allowSceneActivation flag is ignored. This is by design :confused:

Thanks!

No, I started the coroutine in an event handler, that is, once the user pressed a button, the button’s handler invokes the startcoroutine function, it seems to be working in my other scenes. that is why I get a little confused and could not find any working solutions from the web.

Hmm, now it becomes more interesting, as I just found out that allowSceneActivation’s default value is true, as I did not modify anything.

Is there anything that could prevent a scene to be loaded even if it has finished loading at 0.9 and it is actually allowed to activate the scene once loaded?

Thanks guys!

Do you ever set allowSceneActivation to false? Apparently if you do, and you never activate the scene, that will block the loading queue and new scenes will never finish loading (that’s according to this answer here).

-sam

Hi Sam, yep, the allowSceneActivation was actually always true, I used the same code in another situation when I need to load a scene rather than reloading the current scene, it is working properly. It seems Unity ignore the allowSceneActivation this time.

But, if I click somewhere else, such as the task-bar, and then click back Unity (that is, Unity lost focus for a moment), the loaded scene will be activated, so maybe something is blocking my loaded scene from activation?

Hm that kind of sounds like a bug! It might be worth reporting that with a minimal reproducible sample project.

-sam

Thanks! It might be otherwise I would have nowhere to go… Although I would try to see what really happened once Unity lost focus and then re-focused again…:slight_smile: maybe I can imitate that and fool Unity to let it activate my scene…

If I still have no luck by tomorrow, I think I will generate a sample and see if Unity can help me.

Thanks Sam anyway! guys, any other thoughts are always welcomed as well.

@itech4ever any updates? I’m having the same issue.