Unity LoadLevelAdditive and baked light scene settings
I am a programmer for a small game. For our levels, I separated the UI from the level data, so one scene is a scene which contains only the UI, the other scene has all the gameobjects and models and ... the light. So when loading a level, I first load the UI scene (LoadLevel), then the actual play scene (LoadLevelAdditive). Now that our graphics guy wants to bake some lights, he is telling me it doesn't work, because whatever his settings in the play scene, Unity ignores them and uses the settings of the UI scene. He also tells me we cannot just ignore the light settings of the UI scene ... So my question is, how do I make Unity ignore the light settings of a certain scene (UI scene in my case) or how can I enable a settings override? Thanks.
Maybe this is a kind of workaround.
Keep level scene as principal scene with baked lights.
Ignore LoadLevelAdditive that seems useful for other stuff (“This is useful for creating continuous virtual worlds, where more content is loaded in as you walk through the environment.”)
Keep the UI scene as for developement but put all the scene tree under a root (say UIRoot) node.
When you modifiy UI schene export or store UIRoot as prefab. From level scene reference UIRoot prefab.
I have faced this issue earlier , and found a nice solution too 🙂
- Make different scenes for all the levels.
- Put all the game objects inside an empty parent.(optional)
- Bake the Light Maps for all these individual scenes.
- Unity will create a folder with the scene name in which you can find these light maps.
- Now drag and drop all the light maps and the objects into the resources folder.
- You can now delete the level scenes as they wont be needed anymore.
- Now when you want to LoadLevelAdditive , you instantiate the prefab which holds the object for a particular level and assign the light maps programatically.
Here is the code 🙂
//Load Level Model GameObject prefab = Resources.Load ("LevelPrefabs/Level"+level_name+"Prefab") as GameObject; GameObject instance = Instantiate(prefab, Vector3.zero, Quaternion.identity ) as GameObject; //Load LightMap LightmapData lightmapData = new LightmapData; lightmapData = new LightmapData(); lightmapData.lightmapFar = Resources.Load( "LightMaps/Level" +level_name + "/LightmapFar-0", typeof(Texture2D)) as Texture2D; lightmapData = new LightmapData(); lightmapData.lightmapFar = Resources.Load( "LightMaps/Level" +level_name + "/LightmapFar-1", typeof(Texture2D)) as Texture2D; LightmapSettings.lightmaps = lightmapData;
The light map array length depends upon how many light maps are baked for the scene , accordingly you have to tweak the code.
If you have multiple scenes loaded in the editor, you must change the one from where you want to use the settings to the active scene.
So if you have both UI and level scene, and want to bake lights to the level scene, make it active first and bake then.
This is documented in https://docs.unity3d.com/Manual/MultiSceneEditing.html
My experience may be a bit of a corner case but my lightmaps stopped working via additive scene loading when I had a blank skybox (no material set via the editor) that was cached and then set via:
_oldBlankSkybox = RenderSettings.skybox; // RenderSettings.skybox was not set // then, at a later date: RenderSettings.skybox = _oldBlankSkybox; // the skybox was reset to the blank one from above // lightmaps following this do not load correctly
This has been commented on via
LoadLevelAdditive is supported for lightmaps like in 4.x but currently not for Realtime GI.
We are working on making this work for both lightprobes + realtime GI.
The approach we are going for is:
* You load all scenes that you will load together via EditorApplication.LoadSceneAdditive
* Then you bake
Unity will then split the data based on which scenes require it and load enlighten systems based on what it needs for the active set of scenes.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport