Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by xproject2013 · Nov 02, 2015 at 11:05 AM · c#scripting problemlightmappingunity 5.2

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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-

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Nov 02, 2015 at 03:27 PM 0
Share

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.

avatar image xproject2013 · Nov 02, 2015 at 06:06 PM 0
Share

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

avatar image Statement · Nov 02, 2015 at 07:21 PM 0
Share

Edit: Ok, I updated my answer.

avatar image xproject2013 Statement · Nov 04, 2015 at 02:16 PM 0
Share

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

avatar image xproject2013 · Nov 03, 2015 at 01:27 PM 0
Share

Thanks for the update! $$anonymous$$orrow i'll have time to make test and verify your theory

avatar image ImFromTheFuture xproject2013 · Aug 22, 2016 at 01:26 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges