Search Unity

Query Modified Properties on ObjectOverride

Discussion in 'Prefabs' started by JohnAustinPontoco, Feb 22, 2021.

  1. JohnAustinPontoco

    JohnAustinPontoco

    Joined:
    Dec 23, 2013
    Posts:
    283
    Hi,

    I have been able to access the modified components on a PrefabInstance using
    Code (CSharp):
    1. PrefabUtility.GetPrefabOverrides()
    However there doesn't seem to be a way to get *which* fields on the object were changed. I'm currently looking at the ObjectOverride class.

    How can I get this information?
     
  2. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    246
    JohnAustinPontoco likes this.
  3. JohnAustinPontoco

    JohnAustinPontoco

    Joined:
    Dec 23, 2013
    Posts:
    283
    Oh man, I didn't know about that property!

    Like a fool, I ended up writing a SerializedObject diffing algorithm to find properties that were different than the parent. That definitely seems much cleaner.
     
  4. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    246
    Disassembling the Unity's editor functions is usually a very good method to see how things are done or should be done. Sometimes it leads you to easy answer, and sometimes to some native calls which means it's not possible to do it by yourself.
     
  5. JohnAustinPontoco

    JohnAustinPontoco

    Joined:
    Dec 23, 2013
    Posts:
    283
    mahdi_jeddi likes this.
  6. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    219
    Last edited: Mar 16, 2021
  7. JohnAustinPontoco

    JohnAustinPontoco

    Joined:
    Dec 23, 2013
    Posts:
    283
    Oh man, that seems like exactly what I want. Finding these methods sometimes is tricky (especially given how massive PrefabUtility is). Thanks for the pointer!