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
0
Question by Capricornum · Apr 19, 2019 at 01:02 PM · assetinstancecustom editoroverride

Apply changes on asset to instance

I have a custom editor displaying some properties of my custom class "Room" in the inspector. alt text

Whenever I change one property on the asset all the instances are updated automatically. Unless of course I have overriden that specific property on the instance. Now I would like to make sure that whenever I change the property on the asset, all instances are updated regardless of whether they are overriden or not. But I don't know how to find all the respective instances in the scene in order to change them. So my question is how does Unity do it? It needs to find all instances and update them somehow once an asset is changed. And how could I do it?

Thank you for your help.

bildschirmfoto-2019-04-19-um-145606.png (92.8 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
Best Answer

Answer by DiegoSLTS · Apr 19, 2019 at 03:07 PM

I guess you could use Object.FindObjectsOfType() to get all objects with that component, then use PrefabUtility methods.

You can make sure the object is an instance of the prefab you're editing using GetCorrespondingObjectFromSource. You can make sure the instance is still connected to the prefab with IsDisconnectedFromPrefabAsset.

Once you confirmed it's a connected instance of the prefab you can change the value, but you probably need to get the serializedObject for that instance if you want the changes to be persisted: https://docs.unity3d.com/ScriptReference/SerializedObject.html

Anyway, all this sounds like a really bad idea, you'll be doing exactly the opposite of what prefab overrides are intended to do. It might be better if you make a script that checks all prefab instances of the scene on reverts the properties that are not supposed to be overriden. Check other methods of PrefabUtility, like: https://docs.unity3d.com/ScriptReference/PrefabUtility.RevertPropertyOverride.html

With this approach you can run the script when you open a scene and it'll "fix" any prefab instance overriding those values on the scene. The other solution will only work on objects on currently open scenes.

Comment
Add comment · Show 1 · 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 Capricornum · Apr 19, 2019 at 03:38 PM 0
Share

Thank you for the detailed answer. It's all I was looking for. You are right. I am following a wrong path. Going against the system. RevertPropertyOverride seems like a better solution. Thanks again!!!

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

108 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 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 Editor serializing data in prefab instance. 0 Answers

Cost of loading manually modified instances at runtime, on mobiles? 1 Answer

Nested ScriptableObject assets? 1 Answer

Object references in a custom editor 2 Answers

Is there a way to override a function in each instance of the same script? 3 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