This happens in pretty much every scene I load a new scene async:
-
I load the next scene async via
async = SceneManager.LoadSceneAsync(sceneName);
-
I turn off allow scene activation which is SUPPOSED to NOT load the next scene when ready:
async.allowSceneActivation = false;
-
No matter where I am in code, it will just destroy my scene and go to the next one.
I’ve reproduced this in several ways:
- If I alt+tab over to visual studio before or while async was loading and alt+tab over ANYTIME later, it’ll destroy my current scene and shoot me over the next scene.
- If I have a smaller scene with a really fast PC, it seems to preload the scene faster than the next line of text to
allowSceneActivation = false;
and it’ll (again) abruptly launch me to the next scene.
- If I sneeze (joke, but seriously, it can also happen “randomly”)
(Again, ONLY in the editor – this doesn’t happen when compiled)
I reported this bug about 6 months ago
anyone else experience this? Devs, any chance of a fix soon?
EDIT: Seems relevant - Unity Issue Tracker - [LoadSceneAsync] allowSceneActivation flag is ignored in Awake() – someone a few months ago said “Doesnt work even outside of awake()”. I tried moving to start() and still having issues.
Any word? I recently submit a bug report. I’m wondering if others have this.
try LoadSceneMode.Additive
I think the overload of LoadSceneAsync that you are using (.Single) is supposed to do what you are experiencing, is it not?
At least I would consider it undefined behaviour.
Simply load additively and then destroy the initial scene yourself. That works fine.
It’s definitely not normal that it does what it’s supposed to in the player and editor, but only does this in the editor when i unfocus then refocus Unity after a scene is preloaded.
Nothing is supposed to happen until AllowSceneActivation = true.
At least the bug only occurs in the editor, whew… otherwise on the login screen, you could just alt+tab to browser, alt+tab back in and you’re logged in (in the next scene) without credentials! Oops!
allowSceneActivation = false to preload, then setting to true when you’re ready to swap scenes isn’t standard? I don’t understand – could you possibly explain what you mean further?
I will try additive – what is the downside of additive? All the tutorials I see have been with AllowSceneActivation off, yield til ready, then set AllowSceneActivation to true to swap.
EDIT: It’s reproduced every time. Standby for a video cap.
Sure, but that’s not something that can happen in a real game.
Obviously the server wouldn’t even spawn a playable character (or whatever it is the player has/gets in your game) for the player who glitched his way in.
In my game there is a menu/login screen as well, and then a set of scenes that makes up the actual “ingame” state.
However we simply have a loadscreen from login → ingame.
We could do some pre-loading as well, sure.
In that case I think we would just let the scene be loaded and activated.
That works without any side-effects because our “main-scene(s)” are simply static geometry of a level (sure, sounds and animated props in the world as well, but no actual NPCs).
The main scene camera is a) very far away from the world center (0,0,0) so it wouldn’t be a problem even if it had a sound listener attached and b) it has a culling mask set to only render the main menu. And even that could be removed when you simply set a full-size UI image/sprite as background.
There is no downside. It will simply load the scene “in addition” to the initial scene.
So you will have to unload your “main menu” (for example) yourself, and you’ll have to set the new scene to be the active scene as well (because new objects spawn in the active scene).
Those things are really easy to do though.
Its very possible that there is indeed a bug, but to me it also sounds like you might have a small design problem in how you handle scene transitions and game state.