Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

About loading Lightmaping data from scene with additive mode

Discussion in 'Global Illumination' started by infmatrix, Apr 3, 2020.

  1. infmatrix

    infmatrix

    Joined:
    Nov 14, 2019
    Posts:
    6
    Usually,we have one Main.unity scene and several battle field scene .Main scene contain gameobejcts with logic controller scripts ,and battle field scene only contains mesh or terrain information.Also the battle field scenes have their owns lightingdata,
    In runtime we would like to load or unload battle field scene many times.meantime we shouldn't delete objects in main scene.so SceneLoadMode.Single is not proper load type to load battle field scene. Then only SceneLoadMode.Additive is left to us.While when using SceneLoadMode.Additive directly, the lighting data couldn't show normally,just black and white picture. the lighting data is not load directly.
    There is one way to solve this: SceneManager.MergeScenes

    Code (CSharp):
    1. Scene mainScene = SceneManager.GetActiveScene();
    2.                     Scene battleFieldScene = SceneManager.GetSceneByName(battleFieldSceneName);
    3.                     SceneManager.MergeScenes(mainScene , battleFieldScene );
    Then the new problem comes, you can't unload the battlefield scene directly.'cause there is only one scene when battle field scene is loaded. so the lighting data is still there.

    Also I have a way to solve this:
    Code (CSharp):
    1. SceneManager.LoadScene("MainSceneName")
    Another problem:
    The objects in main scene is loaded repeatedly.

    New solution:
    Have a record script to save info whether the main scene is first time to load.
    Code (CSharp):
    1. public class Common
    2. {
    3.     public static bool isMainSceneFirstTimeLoaded = false;
    4. }
    Then each root object in Main scene have a script in awake method, like this:
    Code (CSharp):
    1.     void Awake()
    2.     {
    3.         if (Common.isMainSceneFirstTimeLoaded ) Destroy(gameObject);
    4.     }
    5.  

    It seems no any other problem . But the script is not gracefull at all. Once there are some logic like OnLevelLoaded th main scene, you need fixed it any where. Meantime you should set Common.isMainSceneFirstTimeLoaded = true after mainLogic runned, That's to say you need to take care of the scripts execude order. SooooooooooooPainful!!!!!!!!!!!!!!

    Now I want to ask that:
    1.why lighting data could not be load with LoadSceneMode.Additive?
    2.why not giving a choice for developer to select which lightmaping setting or lighting data to use when using LoadSceneMode.Additive?


    or any new solution to solve this?
    I also check some posts to say that the prolem has been fixed in Unity 5.0,while still not in 2018.4.2.

    btw,I packed the scene data into assetbundle as streaming scene bundle.and load scene after finishing load the bunle .I think the bundle is not the keypoint to this.
     
    Last edited: Apr 3, 2020
    Gekigengar likes this.
  2. thefranke

    thefranke

    Unity Technologies

    Joined:
    Jun 20, 2015
    Posts:
    153
    Hey infmatrix,

    additive scene loading should properly merge your lighting data and display it in a scene. How is your scene lit? Do you use lightmaps and/or lightprobes in your additive scenes? Are there any differences in the Lightmap Settings between the main scene and the additive scenes?

    Two important points up front:
    1. If an additive scene has different Lightmap Settings than the main scene it is being added to, there can be problems when merging baked lighting data.
    2. If you are using Lightprobes, these are not merge-able until 2019.3.

    > why not giving a choice for developer to select which lightmaping setting or lighting data to use when using LoadSceneMode.Additive?

    We are introducing Lightmap Settings assets in 2020.1 which are linked to one or multiple scenes. This makes it much easier to change settings in a lot of additive scenes.

    Cheers,
    Tob
     
  3. infmatrix

    infmatrix

    Joined:
    Nov 14, 2019
    Posts:
    6
    Glad to receive your reply. Expecting the finally version of 2020.1
    Now I find a new way to solve it:
    Call SetActiveAcene when finish additive load ,then the lightmap should be loaded properly.
    When back to main scene,unload the battlefield scene.

    Btw, the lighting data is always follow the path of Unity scene file,could it be modified?
     
    Last edited: Apr 7, 2020
  4. thinkcg

    thinkcg

    Joined:
    Sep 16, 2015
    Posts:
    3
    Hi,Now I additive load,then SetActiveAcene,But main scene's lighting is error.
     
  5. thefranke

    thefranke

    Unity Technologies

    Joined:
    Jun 20, 2015
    Posts:
    153
    Are the Lightmap Settings of both, your additive and your main scene, compatible? If they are not, it does not matter which scene is active and which scene is additively getting loaded, there will be an issue with the Lightmaps.
     
  6. thinkcg

    thinkcg

    Joined:
    Sep 16, 2015
    Posts:
    3
    tks!My main scene is no baked lighting,only realtime lighting, additived scene is baked lighting
     
  7. cp-

    cp-

    Joined:
    Mar 29, 2018
    Posts:
    77
    @thefranke can the lightmaps be "merged" in the scenario @thinkcg describes? "merged" in quotes because the main scene would not have lightmaps.
     
  8. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    706
    Hello, additive scene does not work with GI again even with same lightmap settings in 2022.2.0b16.
    Report issue IN-23942
     
    Last edited: Nov 24, 2022
    angiemon and Pema-Malling like this.
  9. GoinPlaces

    GoinPlaces

    Joined:
    Nov 15, 2017
    Posts:
    8
    Hi! Hope it's okay to hijack this for another issue regard additive scenes/lightmaps.

    So what we do is basically loading scenes additively (the user can do this themselfes by choosing which scenes to load, the main scene is one with all the UI etc. Also, we're using addressables, if that is relevant in an way or form)

    Furthermore, there is a "lights off" function, which basically replaces/changes all the lighting Data:
    -Replaces Lightmaps with prebaked ones
    -replaces cubemaps of reflection probes with prebaked ones
    deactivates lightprobes (dynamic objects get their lighting from environment ambient light (and alternatively also user-placed lights)
    -disables GO with all the mixed lights inside (to disable the direct realtime lights)
    -disables emission in the glowing lamp materials

    So far so good, everything works fine, cool.
    (Additional info: there's a script in each room where you have arrays to define the "dark" lightmaps, cubemaps and materials to deactivate the emission, there always has to be the one from the main Scene too, otherwise everything looks pretty F*ed up, because that lightmap is always in every scene)

    Now to is our problem: When we load a scene, use our lights off function and then change to another scene (or this one again) things get weird, the default state (lights on) looks fine, but in the lighting tab you can see that there's the lightmaps of the scene PLUS all the lightmaps from the previously opened scenes?! The Room after switching the lights off looks flat and wrong, although the amount of lightmaps (and also which lightmaps) seems to be correct.

    HELP?! :((