Search Unity

[Solved] SceneManager.LoadScene() make the scene darker... a bug?

Discussion in 'Global Illumination' started by alexeu, Jul 26, 2018.

  1. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257
    Hi everyone,
    i dont want to waste your time but if you would make a test, that will take less than 2 minutes.
    Just take a default new scene and add a 3d gameobject with a material (not very dark).
    Attach the (basic) script to the GO (or wathever). The script just reload the scene when the spacebar is pressed (as you can see).

    Here after reloading the scene, the light (basic Directional light) seems loosing the half of its original intensity.
    But nothing has changed in the inspector. Same intensity for Half light rendering(?!).
    Other thing : the hierarchy is all collapsed...

    What's wrong?
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class TestSceneScript : MonoBehaviour
    5. {
    6.     void Update ()
    7.     {
    8.         if (Input.GetButton("Jump")) // Any button you wish
    9.         {
    10.             print("Scene has been reloaded");
    11.             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    12.         }
    13.     }
    14. }
    15.  
    Thank you for making the test.
     
  2. V_Kalinichenko

    V_Kalinichenko

    Unity Technologies

    Joined:
    Apr 15, 2015
    Posts:
    16
    Hey,

    Thanks for reporting the issue!

    This bug is known and is related to ambient light probe always being reset to zero after reloading the scene through the script: https://issuetracker.unity3d.com/issues/materials-albedo-ignored-on-restart. As you may see, it has already been fixed in Unity 2018.2.0f2 along with the upcoming 2018.3 version.

    Also, it's worth noting that this bug has a workaround: if you disable Auto Generate checkbox in the Lighting settings window, resetting of ambient probe won't happen.

    I hope my answer was helpful. Cheers!
     
    Last edited: Jul 27, 2018
    Aldeminor and alexeu like this.
  3. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257
    Thank you w1shmast3r for your answer. And yes that was Helpful :).
    I'm still using 2017.3.1f1.
    The issue seems not happening when using Post Processing.

    Thanks again
     
    V_Kalinichenko likes this.
  4. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    I'm using Unity 2020.3.4f1

    I updated the code.

    I attached the code to a Cube and when I press the key (space) the cube goes darker. The hierarchy is also collapsed.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. public class TestSceneScript : MonoBehaviour
    4. {
    5.     void Update ()
    6.     {
    7.         if (Input.GetKey(KeyCode.Space)) // Any key you wish
    8.         {
    9.             Debug.Log("reloaded");
    10.             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    11.         }
    12.     }
    13. }
     
  5. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    The "Light Probe Visualization" setting seems to already have Auto Generate unticked....
     
    Heriloga likes this.
  6. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    The simplest work-around I've come across is:

    Go to Window>Rendering> Lighting >Environment

    In Environment Lighting set Intensity Multiplier to 0

    In Environment Reflections set Intensity Multiplier to 0
     
    a17714375388, nixalott and tokar_dev like this.
  7. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    164
  8. Heriloga

    Heriloga

    Joined:
    Apr 19, 2021
    Posts:
    1
    Any working solution for this bug?
     
    unnanego likes this.
  9. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    Did you try post #6?
    BTW post #4 is a quick method for testing the presence of the bug....
     
    namqwerty12345 likes this.
  10. razamondo

    razamondo

    Joined:
    May 22, 2021
    Posts:
    1
    A workaround in for my problem in Unity 2020.3.8f1
    When I reloaded the active scene it would have the same effect as changing the lighting environment and reflections multipliers to 0.

    My solution was to generate lighting next to the greyed out auto generate box under Window > Rendering > Lighting.
    After generating once manually when I reload the scene with a script lighting in my scene remains at full brightness.

    Posting as this is the first thread that showed up when googling to maybe help out the next person to google this problem.
     
  11. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    That's a great solution - it makes the lighting go from bright to bright. (with mine it went from dark to dark)...
     
  12. selvendranks

    selvendranks

    Joined:
    Apr 8, 2021
    Posts:
    3
    If this problems occurs in built game . Then change graphics setting to legacy vertex lit .it worked for me.
     
  13. Nikil07

    Nikil07

    Joined:
    Jul 6, 2020
    Posts:
    2
    This works. OMG this is such a weird bug.
     
    jiahern likes this.
  14. concretegames

    concretegames

    Joined:
    Dec 2, 2016
    Posts:
    15
    a bit late, for me it worked by ticking and un-ticking Auto Generate from the Lighting window, and cancel generating lightmaps.
     
  15. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
  16. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I've been having this problem as well in Unity 2020.3.8f1, however I've also managed to get this issue on mobile build.
    My situation is a bit different, since I am actually using no pre-baked lighting or light probes at all. My project is based on Google's Maps for Unity package, so prebaked lighting is completely irrelevant for me.

    My setup is first loading in a bootstrap scene without camera or lights and then additively loading in the main game scene. Both scenes share the same Light Settings asset with all settings disabled.
    Interestingly, if I build my project with the bootstrap scene open in editor, I get the faulty dark lighting, but when I build with the main game scene open the resulting lighting in the build is correct.
     
  17. Corwin375

    Corwin375

    Joined:
    Apr 3, 2018
    Posts:
    1
    I've just updated to the latest LTS - 2020.3.18f1 and the issue is still there. Changing Rendering options to 0 or changing the default skybox to none helps, it does require to readjust light settings, which can be a bit of an extra work across multiple games.

    Any ideas if this going to be fixed in 2020.3 LTS?
     
  18. peterroth124

    peterroth124

    Joined:
    Aug 5, 2019
    Posts:
    1
    This works
     
  19. TomazMB

    TomazMB

    Joined:
    Oct 11, 2020
    Posts:
    38
    Hello, I can confirm that this bug still persist in version Unity 2020.3.18f1. I have followed the Project Boost from Gamedev.tv and in the lecture "Respawn using SceneManager". After respawning of my rocket, the light intensity in the scene is much darker -> see the picture. The code was:

    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class CollisonHandler : MonoBehaviour
    {
    void OnCollisionEnter(Collision other)
    {
    switch (other.gameObject.tag)
    {
    case "Friendly":
    Debug.Log("This thing is friendly");
    break;
    case "Finish":
    Debug.Log("Congrats, yo, you finished");
    break;
    case "Fuel":
    Debug.Log("You picked up fuel");
    break;
    default:
    ReloadLevel();
    break;
    }
    }

    void ReloadLevel()
    {
    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    SceneManager.LoadScene(currentSceneIndex);
    }
    }

    Someone from Unity, can you confirm it is a bug? Thank you.
     

    Attached Files:

  20. TomazMB

    TomazMB

    Joined:
    Oct 11, 2020
    Posts:
    38
    Hello, I can also confirm that this metod worked as a solution:

     
  21. mucahiterenozkur

    mucahiterenozkur

    Joined:
    Dec 8, 2020
    Posts:
    1
    This works on me too, thanks a lot my friend :)
     
  22. Dreamaster1111

    Dreamaster1111

    Joined:
    Nov 7, 2021
    Posts:
    3
    It works! Thank you!
     
  23. GamesbyJP

    GamesbyJP

    Joined:
    May 20, 2018
    Posts:
    62
    Bumping because I encountered the same issue.
    Using 2020.3.20f1.
     
  24. GamesbyJP

    GamesbyJP

    Joined:
    May 20, 2018
    Posts:
    62
  25. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
    Hey. Are you using Auto Generate lighting? How are your settings for environment lighting set, and did you try any of the workarounds in the thread?
     
  26. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
    I'm gonna drop some information about environment lighting in this thread, in case someone finds it helpful.

    What we refer to as environment lighting roughly speaking consists of 2 elements, ambient lighting and reflections from the skybox. With default settings in the Environment tab (Environment lighting source = Skybox, Environment reflections source = Skybox) both of these elements are baked. Concretely, the 'Ambient Probe' describes ambient lighting while the 'Default Skybox Reflection' cubemap controls default environment reflections - it's like a fallback for reflection probes. The latter is only exposed when using Environment reflections source = Custom.

    Not too long ago, Auto Generate lighting was changed to no longer default to enabled in most cases. Since we previously relied on this default to bake the Ambient Probe and Default Skybox Reflections for newly created scenes, this change caused scenes to be missing said data until a first bake. To alleviate that, we introduced a new system which would automatically bake these pieces of data for scenes where a first bake had not already occurred. That system was backported to various LTS versions.

    The baked data is stored as temporary files in the GI Cache, and we've had some issues with that behavior in the past, most of which have either been fixed or are currently being investigated. My best advice is to not rely on the data being present at all times - for now, it's mostly useful when previewing a scene in editor. To ensure that a scene has necessary baked data for environment lighting, one should at some point perform a manual bake on the scene using the Generate Lighting button. I suspect that simply performing this first time bake will eliminate the issues a few of the people in here are experiencing, but don't hesitate to open bug reports if that isn't the case.

    I appreciate that this isn't always possible to do, for example if a scene is created from scratch at runtime, or if you want to dynamically change the skybox and/or other things that may affect environment lighting. Unfortunately, it isn't currently very straight forward to rebake data for environment lighting at runtime, although it is still possible. To rebake the ambient probe, one can call DynamicGI.UpdateEnvironment or use RenderSettings.ambientProbe to set it manually to some predetermined SH coefficients. As for the Default Skybox Reflection cubemap, it is a little more involved. My best workaround is to use Unity's built in functionality for baking reflection probes at runtime, and then updating the cubemap manually. Below is an example script which shows one way to do this:
    Code (CSharp):
    1. public class UpdateSky : MonoBehaviour {
    2.     ReflectionProbe baker;
    3.  
    4.     void Start() {
    5.         baker = gameObject.AddComponent<ReflectionProbe>();
    6.         baker.cullingMask = 0;
    7.         baker.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
    8.         baker.mode = ReflectionProbeMode.Realtime;
    9.         baker.timeSlicingMode = ReflectionProbeTimeSlicingMode.NoTimeSlicing;
    10.  
    11.         RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
    12.         StartCoroutine(UpdateEnvironment());
    13.     }
    14.  
    15.     IEnumerator UpdateEnvironment() {
    16.         DynamicGI.UpdateEnvironment();
    17.         baker.RenderProbe();
    18.         yield return new WaitForEndOfFrame();
    19.         RenderSettings.customReflectionTexture = baker.texture;
    20.     }
    21. }
    Putting this script on a GameObject in the scene should allow you to update both the ambient probe and default skybox reflection by calling the
    UpdateEnvironment
    coroutine. Notice the use of
    baker.cullingMask = 0
    such that the reflection probe only sees the skybox.
     
  27. thetimmy

    thetimmy

    Joined:
    Nov 15, 2021
    Posts:
    1
    This also works for me. They should include this fix in the Unity Tutorials (Junior Programmer) because that is where I first encountered the problem.
     
  28. sakus

    sakus

    Joined:
    Oct 9, 2013
    Posts:
    47
    What setting is this?

    I have this problem on Unity 2021.2 in two projects across different platforms - everything is fine in editor but builds are missing the environmental light totally. I can replicate the same (wrong) look in editor by setting environmental light to skybox and intensity 0 or color black.

    No matter what I try (realtime, baked, auto-bake, bake manually, clear baked stuff, what ever) I can't seem to make it look like it should in any of my builds, it's driving me absolutely mad.
     
    Last edited: Jan 17, 2022
  29. tokar_dev

    tokar_dev

    Joined:
    Feb 1, 2017
    Posts:
    9
    I switch Rendering>Lighting in section Environment: Environment Lighting Source: to Color. It works for me.
     
  30. Davidpander

    Davidpander

    Joined:
    Feb 20, 2021
    Posts:
    1
    THANK YOU!!!
     
  31. unity_V8bZCn-egVGPYw

    unity_V8bZCn-egVGPYw

    Joined:
    May 5, 2021
    Posts:
    2
    I'm using unity 2020.3.25f1 and had the same problem even on a real android device.
    Finally, I figured out where the problem is.
    The problem is that the directional light settings in your first scene are different from other scenes.
    In my case, I had a Loader scene. I copied directional light settings from one of the other scenes to the Loader scene and that's it. my problem was gone.
     
    aloften and josealfu like this.
  32. kupikey

    kupikey

    Joined:
    May 12, 2015
    Posts:
    1
    Thanks for solving the issue for me unity_V8bZCn-egVGPYw !
    This only happens if scenes don't have the same directional lightning object in scene. After I copied the same directional light to all scenes, there was no more problems!
     
  33. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    ...reading this entire thread about a simple task to load a next scene. wow. @kupikey - your solution is the one, and only one, which worked! Thank you:)
     
  34. josealfu

    josealfu

    Joined:
    Jan 16, 2022
    Posts:
    4
    This was the winner for me. Thanks.
     
  35. Bmco

    Bmco

    Joined:
    Mar 11, 2020
    Posts:
    54
    I had a similar problem, but the Rendering/Lighting Window is very deceptive about which Scene you're changing the settings on. I had a Main Start Up Scene that I was accidentally setting all the light options for. When I changed the active scene to a level scene, I lost my Skybox. If you're going to change Lighting Settings, make sure all other scenes are unloaded.

    Ideally, the Rendering/Lighting Window would have a dropdown displaying the Scene you're changing the properties for.
     
  36. PsiconLab

    PsiconLab

    Joined:
    Oct 9, 2017
    Posts:
    27
    Yep. This worked.

    Here's a complete file (had to tweak the customReflection bit) for copy and pasting.

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.Rendering;
    4.  
    5. public class UpdateSky : MonoBehaviour
    6. {
    7.     ReflectionProbe baker;
    8.  
    9.     void Start()
    10.     {
    11.         baker = gameObject.AddComponent<ReflectionProbe>();
    12.         baker.cullingMask = 0;
    13.         baker.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
    14.         baker.mode = ReflectionProbeMode.Realtime;
    15.         baker.timeSlicingMode = ReflectionProbeTimeSlicingMode.NoTimeSlicing;
    16.  
    17.         RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
    18.         StartCoroutine(UpdateEnvironment());
    19.     }
    20.  
    21.     IEnumerator UpdateEnvironment()
    22.     {
    23.         DynamicGI.UpdateEnvironment();
    24.         baker.RenderProbe();
    25.         yield return new WaitForEndOfFrame();
    26.         RenderSettings.customReflection = baker.texture;
    27.     }
    28. }
     
    TigerHix and Pema-Malling like this.
  37. aloften

    aloften

    Joined:
    Aug 25, 2017
    Posts:
    18

    This fixed it for me in 2021.3.11f1

    I did not need my lighting in my menu scene so I deleted it(which was coming anyways).

    If anyone else is experiencing this, using an async scene manager that is always loaded is a potential solution. You could probably run your lighting from there and just turn things on or off with a lightManager script. IF the bug is truly related to having a different type of lighting, this SHOULD fix it since the lighting would not be destroyed between scenes.
     
  38. TomazMB

    TomazMB

    Joined:
    Oct 11, 2020
    Posts:
    38
    Hi,

    I've tried your method since I had the same issue that in one scene the lighting was on and after switching from another scene to before OK scene, this scene appears darker, as if the lighting was set to off. But what I did was that in the first scene I set both your settings to 0 and save, and then I set both settings back to 1. The lighting in the second scene (which was switched from the first scene) appeared as it should - lighting is now back on. I'm using Unity 2022.2.1f1 Personal. I still think this is a bug who also appear in this recent version. Thank you.
     
  39. alexu

    alexu

    Joined:
    Jun 19, 2014
    Posts:
    8
    Works, thank you!
     
  40. TigerHix

    TigerHix

    Joined:
    Oct 20, 2015
    Posts:
    69
    Worked with additive scenes. Huge saver! Thanks!
     
  41. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    63
    I'm facing the same problem on 2022.3.10f1.

    But my problem is even if I load Scene B from A and they have the same lighting settings, the environment light from Skybox is still been disabled. If it is caused by not baking light data, why the environment light is working when I directly launch Scene B?

    I think it is a bug.
     
  42. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
    The environment lighting used is determined by the currently active scene (https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.SetActiveScene.html) - it's marked in bold text in the hierarchy, and there is only on active scene, regardless of how many scenes are loaded. If the currently active scene has been baked, and you still aren't seeing environment lighting, feel free to file a bug report.
     
  43. XJonOneX

    XJonOneX

    Joined:
    Dec 19, 2017
    Posts:
    114
    Excellent information, worthy of a bump. Generating lighting for all my additive scenes fixed the issue in 2022.3.13f1. I only have one directional light active amongst all the scenes.