Search Unity

Resolved Revert Redundant Property Modifications

Discussion in 'Prefabs' started by keenanwoodall, Mar 25, 2022.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    I'm working on a script that will revert property modifications on a prefab variant if the modification value is the same as the parents.

    I'm using PrefabUtility.LoadPrefabContents to load the prefab in question, and then calling PrefabUtility.GetPropertyModifications to get all modifications via the returned root.

    However, this is where I'm getting stuck as I cannot figure out how to find each property modification's value on the source prefab.
     
  2. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Well it looks like this is unnecessary. In my use-case I just needed to make sure the prefab's parent has it's properties changed before the variant. Unity doesn't serialize changes as property modifications if the property value hasn't changed. I was just changing them values on prefabs in the wrong order, so at the time the variant was changed it *was* different.
     
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    If you do want to do this manually you can create a serialized object from the modifications target object and get the serialized property via the modifications property path. From there you can see the serialized value on the parent prefab and compare it to the modifications value. Although it's a lil awkward cuz the property modification stores its value as a string and the serialized property stores it in a special field corresponding to the serialized property type. I was manually parsing and comparing values until I realized it was unnecessary