• 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 AMAT_Sooraj · Oct 15, 2019 at 10:12 AM · prefabutility

Revert Prefab property override through script

Hi Guys,

I have a situation where materials leaked into the scene due to something I did. But all those materials are in a prefab. Now I want to write an editor script that will find all the materials instances in MeshRenderer.sharedMaterials array in each mesh in the prefab and revert only that particular array element. I tried PrefabUtility.RevertPropertyOverride since I cannot revert the whole object or component or even the entire sharedMaterials array. Only the elements with material instances in it. The problem with PrefabUtility.RevertPropertyOverride is that it takes a SerializedProperty and I'm unable to get the SerializedProperty of the sharedMaterials array or individual elements in it because its a property and not a variable.

Any help would be really appreciated!

Thanks

Comment
Add comment · Show 8
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 misher · Oct 15, 2019 at 10:30 AM 0
Share

If you have changed the material asset there is nothing you could do. It is saved in its asset and it is not a part of some prefab's property. As a prefab property, you have only a reference to the material asset, thus you can revert to point again to some asset or to be null for example, but not to change something that is a property of material itself. In other words, material own properties are serialized in its own asset and not into prefab asset.

avatar image AMAT_Sooraj misher · Oct 15, 2019 at 11:14 AM 0
Share

Yes I know. But my issue is different. $$anonymous$$y materials got leaked into the scene since I used $$anonymous$$eshRenderer.materials ins$$anonymous$$d of $$anonymous$$eshRenderer.shared$$anonymous$$aterials in Editor mode. Its only meant to be used in run time. Now I can sit and revert individual array elements by right-clicking any revert property, but I have over 10k meshes in a scene and 9 scenes. So I just want to write an editor script to do the same.

avatar image misher AMAT_Sooraj · Oct 15, 2019 at 11:54 AM 0
Share

Hmm, you could search for each mesh if there is an original material asset and set sharedmat = ref asset ins$$anonymous$$d of (instance). Although I can not imagine what criteria you can use in search.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Marc-Saubion · Feb 13 at 03:13 PM

Similar issue.

I'd like some renderers to blink red to add some visual cues but don't want to override the prefab material with the original material once it done.

Did you find anything?

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

112 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 avatar image avatar image avatar image avatar image

Related Questions

Unity 4 PrefabUtility.InstantiatePrefab problem in OnPostprocessModel 0 Answers

is there any alternative method for prefab utility in builded apllication??,is there any alternative method for prefabutility in builded application?? 0 Answers

PrefabUtility.ReplacePrefab gives "Shader wants texture coordinates" warning 0 Answers

How to simulate a particle effect from custom editor script button? 0 Answers

How do you Create Prefabs in Script on import. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges