About loading Lightmaping data from scene with additive mode

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

Scene mainScene = SceneManager.GetActiveScene();
                    Scene battleFieldScene = SceneManager.GetSceneByName(battleFieldSceneName);
                    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:

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.

public class Common
{
    public static bool isMainSceneFirstTimeLoaded = false;
}

Then each root object in Main scene have a script in awake method, like this:

    void Awake()
    {
        if (Common.isMainSceneFirstTimeLoaded ) Destroy(gameObject);
    }

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.

1 Like

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:

  • 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.
  • 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

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?

Hi,Now I additive load,then SetActiveAcene,But main scene’s lighting is error.

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.

tks!My main scene is no baked lighting,only realtime lighting, additived scene is baked lighting

@thefranke can the lightmaps be “merged” in the scenario @thinkcg describes? “merged” in quotes because the main scene would not have lightmaps.

Hello, additive scene does not work with GI again even with same lightmap settings in 2022.2.0b16.
Report issue IN-23942

2 Likes

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?! :((