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 stu_chineseroom · Jan 13, 2016 at 09:35 AM · unity 5serializationlightmappingsavingmeshrenderer

Saving changes to MeshRenderer at edit time

Hi,

I'm changing a few properties of the MeshRenderer component on my objects at edit time (e.g. lightmapIndex, lightmapScaleOffset). I also update the LightmapSettings structure since I'm setting up some custom lightmaps. This all seems to work fine, however when I quit and reload the level the changes are gone. If I were making edits to the meshes themselves I'd look at editing the sharedMesh or creating a new asset, but since this is the MeshRenderer components and a general engine structure, I'm not sure how to best proceed.

For what it's worth, I've tried using EditorUtility.SetDirty(), PrefabUtility.RecordPrefabInstancePropertyModifications() etc to make sure I'm notifying the editor of my changes. I can view the intended values in the Lighting/Object tab under Baked Lightmap too.

Any help would be much appreciated. Thanks, Stu

Comment
Add comment · Show 7
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 Fattie · Jan 13, 2016 at 01:01 PM 0
Share

good question

avatar image Baste · Jan 13, 2016 at 01:05 PM 0
Share

How are you editing the changes? If you're using SerializedProperties, you need to use their version of SetDirty (Apply$$anonymous$$odifiedProperties).

If not, make sure that you're calling SetDirty on the $$anonymous$$eshRenderer component itself.

avatar image stu_chineseroom · Jan 13, 2016 at 06:51 PM 0
Share

Hi @Baste, thanks for replying.

I'm currently doing this essentially:

 GameObject go = GameObject.Find(meshName);
 Renderer mr = go.GetComponent<Renderer>();
 
 // Update the values on the $$anonymous$$eshRenderer
 mr.gameObject.isStatic = true;
 mr.lightmapScaleOffset = scaleOffset;
 mr.lightmapIndex = lightmapIndex;
 
 // Throw any dirty flags into the mix that I can find
 PrefabUtility.RecordPrefabInstanceProperty$$anonymous$$odifications(go);
 EditorUtility.SetDirty(go);
 EditorUtility.SetDirty(mr);

As per the code, I've tried setting the dirty flag on the GameObject and the $$anonymous$$eshRenderer component and have tried many combinations thereof. I don't think I can set a dirty flag on the LightmapSettings structure itself, so I'm not sure what I can do to coax that to save either.

Thanks for the help, Stu

avatar image stu_chineseroom · Jan 18, 2016 at 02:49 PM 0
Share

I've additionally tried cloning the objects, setting the new params on the clones and then destroying the originals. Sadly this doesn't work either. I thought perhaps the values might get pulled from the prefab so I use PrefabUtility.DisconnectPrefabInstance() after cloning but to no avail.

I've also tried updating the components on the prefabs themselves, but that didn't seem to make any difference (I changed the hideFlags to allow editing first, just in case).

I'm kinda out of ideas now other than setting the values during Awake() at runtime to make sure they persist during gameplay at least. Any other thoughts?

cheers, stu

avatar image Baste stu_chineseroom · Jan 19, 2016 at 12:06 AM 0
Share

Okay, I've been noticing similar things too, and just replied to a thread on the forums.

At one point, the SetDirty method stopped setting the scene dirty. I'm not sure if it's a bug or a horribly bad idea, but in the mean time, you'll have to manually set the scene dirty when you do a change.

This seems to be done through the very wordy:

 EditorScene$$anonymous$$anager.$$anonymous$$arkSceneDirty(EditorScene$$anonymous$$anager.GetActiveScene());

Try that.

avatar image stu_chineseroom Baste · Jan 19, 2016 at 11:47 AM 0
Share

Hi Baste,

Thanks for the suggestion! I upgraded to Unity 5.3 to get access to EditorScene$$anonymous$$anager but sadly it still doesn't seem to save the $$anonymous$$eshRenderer changes I need. I also tried using Undo.RecordObject from the forum thread as I'd not considered that before but it still doesn't make the changes stick. Perhaps the settings are saved, but the engine is overwriting them with the defaults on-play or reload (e.g. offsetScale is reset to <0, 0, 1, 1>, lightmapIndex to -1).

I'm now beginning to wonder if I'm doing something fundamentally not possible by injecting these lighting values. If I clone an object, create a new shared$$anonymous$$esh copying over the data, create an actual asset from that and then instantiate that into the scene, the $$anonymous$$eshRenderer lightmap values still get reset. :/ $$anonymous$$aybe it's time for a new approach...

Thanks again for the suggestion, much appreciated!

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Editor SerializedProperty how to assign to array with larger data directly. 1 Answer

Binary Serialization (In Editor) - Path Access denied / File not found 0 Answers

How to save custom data types 1 Answer

How are unity references serialized? (instanceID related) 1 Answer

Issues when using Unity Serializer 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