Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by tmdchi · Nov 13, 2012 at 12:18 AM · runtimelightmapswap

How to swap lightmaps?

My guess was that it should be enough with something like this:

 var myLM : Texture2D;
 LightmapSettings.lightmaps[i].lightmapFar = myLM;

Being i a valid index, of course.

It doesn't work as I expected.

In fact, when printing the .name of that lightmapFar, before and after the assignation, the same original name is given. What surprises me most is that, while in play mode, I can assign the texture manually in the lightmapper interface and it gets correctly updated.

Anyone knows how should I do it in order to make it work in runtime from a script?

Thanks!

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
2
Best Answer

Answer by Memige · Nov 13, 2012 at 01:14 AM

Hi there! I just got such a thing working the other week through assetBundles, below is an adaptation that should work for you.

 var myLMs : Texture2D[] = //populate your custom lightmaps
 var lightmaparray : LightmapData[] = LightmapSettings.lightmaps;
         
 for (var i=0; i < lightmaparray.Length; i++) {
     var mapdata : LightmapData = new LightmapData();
     mapdata.lightmapFar = myLMs[i]
     lightmaparray[i] = mapdata;
     mapdata = null;
 }
 LightmapSettings.lightmaps = lightmaparray;

I'm actually a C# guy, so please forgive if I've made any mistakes in translating to js, but I believe this should work.

Comment
Add comment · Show 5 · 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 tmdchi · Nov 13, 2012 at 10:15 AM 0
Share

Interesting... It works! I tried something similar before, but never created and replaced a new complete array. I believe that's the key thing. Thank you $$anonymous$$emige!

avatar image Memige · Nov 13, 2012 at 07:34 PM 0
Share

You are most welcome, glad I could help ^^

avatar image Kraegin · Jan 18, 2013 at 05:38 PM 0
Share

Not to sound like a complete noob, but how do I populate my lightmaps? As in how do I link the folder I have my other lightmaps in to the myL$$anonymous$$s variable?

avatar image Adam-Buckner ♦♦ · Apr 26, 2013 at 11:55 AM 0
Share

$$anonymous$$raegin: You would do this by dragging and dropping your lightmaps from their folder in the project view onto the slots in the array in the inspector.

This is a very common way of working in Unity. Create a public variable to hold a reference or data in your script and populate that variable with a reference or data in the inspector.

avatar image obefa2006 · Feb 03, 2015 at 12:52 AM 0
Share

i'v tried your solution which seams great but i have the follow error message :

"get_lightmaps can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, ins$$anonymous$$d move initialization code to the Awake or Start function"

any idea ? :)

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

12 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

Related Questions

Swapping lightmaps during runtime? 1 Answer

Can I create lightmaps at runtime? 3 Answers

How to add new baked lightmaps to lightmap array? 2 Answers

Blending between 2 lightmaps 0 Answers

change lightmaps at run time? 1 Answer


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