Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Reverting PropertyModification

Discussion in 'Prefabs' started by blunzn, Jul 28, 2020.

  1. blunzn

    blunzn

    Joined:
    Jan 14, 2015
    Posts:
    14
    hi,

    I would like to traverse all PropertyModifications (retrieved via PrefabUtility.GetPropertyModifications(instance)), compare instance value with prefab value, and eventually revert the modification via PrefabUtility.RevertPropertyOverride. For reverting I need the SerializedProperty of the instance object, but the PropertyModification only has a reference to the prefab object. In a more complex prefab, with eventually nested prefabs, variants etc... I dont see a way to access the corresponding instance property to call RevertPropertyOverride.

    Another way to do this would be traversing all SerializedProperties of a prefab instance and check whether SerializedProperty.prefabOverride is true. But then I dont see any way to access the prefab value which is overridden for comparison.

    Any ideas how to do this?

    thanks!
     
    Last edited: Jul 28, 2020
  2. GleyGames

    GleyGames

    Joined:
    Oct 16, 2015
    Posts:
    482
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    You can use
    GetCorrespondingObjectFromSource
    and then find the same SerializedProperty on that object to get the Prefab Asset value.