3
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Thanks, this is not a bad suggestion and we might go with this workaround. I'll try it out and come back to you. \$\endgroup\$ – ElDuderino Sep 7 '15 at 11:47
2
\$\begingroup\$

I have faced this issue earlier , and found a nice solution too :)

Procedure:

  • 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[2];

    lightmapData[0] = new LightmapData();
    lightmapData[0].lightmapFar = Resources.Load( "LightMaps/Level" +level_name + "/LightmapFar-0", typeof(Texture2D)) as Texture2D;
    lightmapData[1] = new LightmapData();
    lightmapData[1].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.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your answer, but we went with dnk's approach, as it works out of the box without any code tinkering. +1 for effort :) \$\endgroup\$ – ElDuderino Sep 10 '15 at 11:32
  • \$\begingroup\$ Are the lightmapData always 2 in Unity? Is it structured that way? Or can the number change? It seems to have changed in current versions. There's -Color, -Dir and -Light. \$\endgroup\$ – SteakOverflow Nov 26 at 16:14
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

This has been commented on via

http://forum.unity3d.com/threads/gi-global-illumination-load-level-additive-rendering-issues.310452/

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.