Search Unity

Question Visualizing nested prefab override values correctly.

Discussion in 'Prefabs' started by Vince-Chimp, May 6, 2021.

  1. Vince-Chimp

    Vince-Chimp

    Joined:
    May 28, 2018
    Posts:
    43
    Hey,

    I am trying to create a small tool for our less tech savvy people to easily display where variables are getting overwritten in complex nested prefab situations.

    So far i have come up with this:

    This works by taking the original component (context menu has a script to open up this window) and calling:
    Code (CSharp):
    1. PrefabUtility.GetCorrespondingObjectFromSource(targetComponent);
    Recursively until it returns null. Then for each level of targetComponent i use:
    Code (CSharp):
    1. PrefabUtility.GetPropertyModifications(targetComponent);
    To get all the modifications and then sanitize and format that a bit to show it to the user.

    1st problem i run into, is that if i want to show "all the base properties" in this same window, i can't because they are not "modifications" And i can't seem to find a way to get "all base properties".

    2nd problem i run into is that Scene overwrites do not work in a similar way, and the same applies to Prefab mode. The top level is always omitted (as seen in the screenshot as well).
    This issue probably comes from me having to use:
    Code (CSharp):
    1. modification.target.GetInstanceID() == nextTargetComponent.GetInstanceID()
    To filter all modifications for the specific current TargetComponent. Which means at the top level, the next targetcomponent upwards is null. So i have no InstanceID() to get the information only related to my current TargetComponent.

    Am i overcomplicating this, or am i missing methods that actually make everything possible for the two issues i run into?
    It is kind of annoying that i can't show the full changes of either the scene or the top level prefab in prefab mode. And not being able to get the bottom level's "full picture" disallows me from showing which properties got overrides at _any_ level above it.
     
    Last edited: May 6, 2021
    Greg-Chimp likes this.