- Home /
AsyncOperation.allowSceneActivation seems to be ignored
Hi all.
I try to preload a main menu scene while playing an intro, and then show that menu when intro is skipped or finished. All posts that I've seen state that if you load scene async with:
op.allowSceneActivation = false;
then op.progress will, hmm... progress up to 0.9f and op.isDone will be false. Then I can manually set allowSceneActivation to true when I want to, and scene will appear. So I wrote this:
private AsyncOperation op;
void Awake()
{
op = SceneManager.LoadSceneAsync(Name, LoadSceneMode.Single);
op.allowSceneActivation = false;
}
void Update()
{
if (op.progress >= 0.9f && m_Proceed)
{
if (!op.allowSceneActivation)
{
op.allowSceneActivation = true;
}
else if (op.isDone)
{
// Switch to main menu processing
}
}
}
But the first time Update is called my async operation has progress = 1f and isDone = true whilst allowSceneActivation = false. My menu comes on screen though I didn't allow it. It does work this way in Single and Additive loading modes. I tried free versions of Unity 5.5.0f3 and 5.5.1p3 and both have the issue.
Am I missing something? How can I preload scene without showing it up on the screen until I want to?
Thanks.
Answer by jahndal · Feb 19, 2017 at 10:57 PM
It's a known bug: https://issuetracker.unity3d.com/issues/loadsceneasync-allowsceneactivation-flag-is-ignored-in-awake
As suggested in a bug report, loading scene in Update() instead of Awake() fixed the problem.
For some reason at the start of the coroutine (before creation of AsyncOperation object) you need to insert:
yield return new WaitForSeconds(0.1f);
Funny enough, inserting yield return null
or yield return new WaitForEndOfFrame
doesnt work any more (probably worked in Unity 2018 and 2019)
This is crazy! I've been smashing my face on my keyboard all day - only to add this yield before the async load..... WHY IS THIS A THING!!!!????
(PS - Thankyou!)
omg! thank you! This was driving me absolutely nuts!
Your answer
![](https://koobas.hobune.stream/wayback/20220612111250im_/https://answers.unity.com/themes/thub/images/avi.jpg)