Search Unity

Bug SceneManager.sceneLoaded reports a LoadSceneMode that doesn't exist.

Discussion in 'Editor & General Support' started by Ultroman, Apr 6, 2022.

  1. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    Using Unity 2020 LTS. There's 1 scene in the build settings. I'm playing it in the editor.

    A script hooks up to the UnityAction SceneManager.sceneLoaded in Awake, and receives the notification that my scene has loaded, as expected. It passes in the parameters (Scene loadedScene, LoadSceneMode mode) to the function I've hooked up.

    However, the LoadSceneMode-value it gives me is 4. The LoadSceneMode-enum has 2 values and they aren't numbered, so the values Single and Additive respond to 0 and 1, respectively.

    When I do Enum.GetName(typeof(LoadSceneMode), mode) it gives me null, because mode is 4. When I put in 0 or 1 in place of mode, it properly prints "Single" or "Additive". I thought I was going insane until I checked that!

    Why is this happening? What does 4 mean, and why isn't it defined in the enum, when it's a value we can receive from the system? Does that mean "Editor"? Or does it mean "Initial Scene Load", since that's started by the system?
     
    Last edited: Apr 6, 2022
  2. RootKiller

    RootKiller

    Joined:
    Sep 6, 2015
    Posts:
    1
    We also had a similar problem I checked the editor executable and it seems there are 7 values in the native part of the engine. My guess is what they mean is below, of course, It would be best to get someone from Unity to provide proper information to us.

    Code (CSharp):
    1. 0 = Single,
    2. 1 = Additive,
    3. 2 = In theory similar to single but also runs some callbacks and does something on the game manager (Profiled LoadSceneMode.Single?)
    4. 3 = Preload manager, load scene editor,
    5. 4 = Preload manager, load scene editor,
    6. 5 = Additive
    7. 6 = Additive
    The callback however is called only
    if(mode <= 2 || mode == 4)
     
    Ultroman and Kurt-Dekker like this.
  3. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    That is fascinating information! Thank you very much :D That is an odd choice, though. Why is that not documented? You get that value whenever you start the game in the editor. I understand that I'm not supposed to be able to start a load using these enum-states myself, but then just warn me when I try to use them or in the documentation, or make separate LoadSceneAsync-functions for the only 2-3 modes that actually work in the exposed version of the function.