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 /
avatar image
2
Question by buskamuza · Aug 05, 2016 at 01:59 AM · lightmappingbaked light

Lightmaps Loaded via Script are Broken After Upgrade to Unity 5.4

In the project, I configure multiple scenes and save the data: objects on the scene, lightmaps and other. When the scene starts, I load saved lightmaps. Also, because I load objects dynamically, I define the lightmap(s) for each object that has a rendered:

 // Load lightmaps
 LightmapData[] lightmaps = new LightmapData[missionLightData.lightmapsNumber];
 for (int i = 0; i < missionLightData.lightmapsNumber; i++) {
     lightmaps[i] = new LightmapData
     {
         lightmapFar = Resources.Load<Texture2D>(GetLightmapPath(missionName, i))
     };
 }
 LightmapSettings.lightmaps = lightmaps;

 // Define lightmaps for the objects
 foreach (MissionLightmapData.LightmapAssotiation lightAssotiation in missionLightData.lightmapAssotiations) {
     GameObject go = GameObject.Find(lightAssotiation.objectName);
     if (go)
     {
         Renderer renderer = go.GetComponent<Renderer>();
         if (renderer)
         {
             renderer.lightmapIndex = lightAssotiation.lightmapIndex;
             renderer.lightmapScaleOffset = lightAssotiation.lighmapScaleOffset;
         }
     }
 }

It worked fine in Unity 5.3. But after upgrade to 5.4, the mission looks black&white. alt text

I also noticed that if I don't touch the scene, everything loads fine in the editor. But as soon as I modify the scene (some other settings are updated by Unity) or if I run the scene, I get same "black&white" effect.

Any ideas what can cause such effect? Maybe Unity stores lightmap associations to the objects somewhere else now?

blackwhite-scene.jpg (99.3 kB)
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 StaggartCreations · Sep 13, 2016 at 08:18 AM

I use the same system and I'm running into the same issue with 5.4. Before, this occurred if the scene where the objects/lightmaps had it's Directional Mode set to "Directional", and since we bake our scenes using Non-Directional lighting (no normal maps) it conflicted. Changing the scene to Non-Directional mode fixes this however.

Now in 5.4 the same issue occurred, and the solution was to set the Directional Mode through script upon loading. This was a relief, however it didn't work in the build, black-and-white like you're seeing.

So I'm assuming this has something to do with the fact that Unity expects Directional Lightmaps, where none are supplied. Perhaps loading a single blank directional lightmap next to all your "Far" lightmaps would do the trick.

Comment
Add comment · Show 4 · 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 DizzyWascal · Sep 28, 2016 at 08:23 AM 0
Share

Hey! Changing the Directional $$anonymous$$ode in script using LightmapSettings.lightmaps$$anonymous$$ode = Lightmaps$$anonymous$$ode.NonDirectional;

Actually worked! Also it worked in build for me! THAN$$anonymous$$ YOU!

avatar image buskamuza · Sep 29, 2016 at 03:28 AM 0
Share

Hm. Interesting. I didn't try this approach. I found out that it helps if the scene has at least some lightmap baked and assigned to it. Then, on the scene, it can be replaced with another lightmap and all works fine. Also, I used light.alreadyLightmapped = true in older versions and it has to be removed now, as it causes the issue described above even with the workaround I described. Thanks for the answer, though. I may try this approach as well.

avatar image StaggartCreations · Sep 29, 2016 at 08:06 AM 0
Share

I've actually managed to resolve my issue yesterday. Under Project Settings->Graphics I had the lightmap modes set to '$$anonymous$$anual' and "Baked Non-Directional" wasn't ticked, that's why it didn't work in the build for me.

in 5.4, the new way to flag lights as baked is through the use of light.bakedIndex = <unique id> https://docs.unity3d.com/ScriptReference/Light-bakedIndex.html

avatar image buskamuza StaggartCreations · Sep 29, 2016 at 07:05 PM 0
Share

light.bakedIndex = <unique id> - I tried this and it doesn't help. I checked the value in the bakedIndex and it is different depending on whether you have some lightmap attached to the scene or not. If I have no lightmap, setting the index doesn't help.

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

67 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 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

Custom lighting model used in light bake 0 Answers

Static objects are dark when lighting is baked 0 Answers

Как управлять UVW атлассингом юнити террейна? How to manage UVW atlas unit terrain? 0 Answers

Failed baking lighting 0 Answers

Indirect baked light not respecting cast shadows flag on renderer or light object. 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