How to switch between two lightmaps in unity 5
Hi, 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
Answer by Statement · Nov 02, 2015 at 03:25 PM
I haven't tested it myself, but it looks like you can use LightmapSettings.lightmaps.
http://docs.unity3d.com/ScriptReference/LightmapSettings.html
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-
If I understand it correctly, you can assign it a new array with your lightmaps.
Or, you can add multiple lightmaps and tell certain renderers to use a different lightmap.
Hi thanks for the answer,
in Unity 4 i did as you explain but in Unity 5 every time that i rebuild the lightmap it delete the old lightmap also if i already save all the textures in another folder.
In unity 4 i already write a script about how to switch the lightmap (http://answers.unity3d.com/questions/970802/multiple-lightmapping-for-a-scene.html#answer-970835) but in Unity 5 the lightmap management is different and i don't know how to achieve what i need
I tested your method (delete the .meta files and change the directory) and i now i have two different set of lightmaps. I don't know how to load dynamically the lightmaps because of their new structure and files na$$anonymous$$g, as i can see it would be enought to change the LightmapSnapshot in order to change all the lightmaps but it's an only editor object so i can't change it and i don't know what to do
Thanks for the update! $$anonymous$$orrow i'll have time to make test and verify your theory
Hey! Did you find a working solution to this? I'm trying to achieve the same thing but loading them dynamically is a huge pain.
Your answer
Follow this Question
Related Questions
How would i modify my current script to remove these UI buttons without killing my pause menu? 1 Answer
Why does NetworkServer.ReplacePlayerForConnection not recognize the instantiated object parameter? 0 Answers
I get a "NullReferenceException" when trying to change the text of a UI text box. 1 Answer
.FindChild("String" + 1) is not the same as .FindChild("String" + integerVariable)??? 1 Answer
[C#] StreamWriter throwing Sharing Violation on path 0 Answers