How to switch between two lightmaps in unity 5

i’d like to know how can i switch between two differente lightmaps of the same scene in Unity 5.
In Unity 4 was quite easy to do it but i don’t have any clue how to do it in 5.
I’m using the last patched versione 5.2.2p2.
Thanks in advance for any help or suggestions

I haven’t tested it myself, but it looks like you can use LightmapSettings.lightmaps.

Edit: It seems that Unity 5 will destroy the Lightmaps when baking new lightmaps, even if the files have been relocated. I figured out a way to keep the lightmaps, but it’s a little hacky.

  • Bake your scene

  • Rename your lightmap folder so you can keep the files

  • Delete LightmapSnapshot from the folder

    (or move it out of the project entirely)

  • Make light adjustments

  • Bake your scene

  • You should now have 2 sets of lightmaps

From this point on, you should be able to set lightmaps using resources.load per your other post, although I have not tested it that far. I tested it to verify the textures are there.

So I figured it out by looking at the Scene yaml for LightmapSettings. It has a GUID reference to LightmapSnapshot. From what I read in the manual, it doesn’t look very important in my eyes, although I did skim it through so you may want to read it too and determine if it seems safe. So from the scenes point of view, all it knows is that it has a LightmapSnapshot. I make the assumption then that LightmapSnapshot has references to the lightmaps. If the scene doesn’t have any LightmapSnapshot, then it also cannot determine which textures to erase, keeping them intact.

It should also be possible to edit the scene file and remove the GUID, although you’d probably have to reload the scene in Unity to flush the memory the editor has. This way you can keep the LightmapSnapshot asset, if for any reason you need it. I don’t know much about it other than it’s binary data.

Theoretically, you could probably also just remove the meta files for the lightmaps as this will cause new GUIDs to be generated, breaking the link from the LightmapSnapshot to the actual textures. (With other words, you should be able to simply copy/move the lightmap files in Explorer/Finder/Whatever, but exclude the meta files).

I hope that solves your problem. Delete LightmapSnapshot, or copy the lightmaps via your file system manager - don’t move/copy the meta files-