Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Async Editor Bug: Shooting straight to the next scene when it shouldn't

Discussion in 'Editor & General Support' started by MrLucid72, Jul 8, 2017.

  1. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    962
    This happens in pretty much every scene I load a new scene async:

    1. I load the next scene async via
      `async = SceneManager.LoadSceneAsync(sceneName);`
    2. I turn off allow scene activation which is SUPPOSED to NOT load the next scene when ready:
      `async.allowSceneActivation = false;`
    3. 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 - https://issuetracker.unity3d.com/issues/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.
     
    Last edited: Jul 8, 2017
  2. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    962
    Any word? I recently submit a bug report. I'm wondering if others have this.
     
  3. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    962
  4. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
  5. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    962
    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.

    https://docs.unity3d.com/ScriptReference/AsyncOperation-allowSceneActivation.html

    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.
     
  6. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    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.