Search Unity

Request: override component with derived component in variant

Discussion in 'Prefabs' started by p-lindberg, Jul 16, 2019.

  1. p-lindberg

    p-lindberg

    Joined:
    Feb 19, 2019
    Posts:
    7
    Hello!

    A common use case for prefab variants is to create more specialized versions of prefabs, which often requires creating more specialized versions of the scripts that control them (unless you're a hardcore component based object model masochist). Unfortunately, with the way things currently works, this requires deleting the base version of the component inside the variant and adding the derived one in its place, which means that the values of fields do not propagate from base to variants.

    I suggest adding the option to override a component in a prefab variant with another component that derives from the original component, while keeping the values of serialized fields. Since a derived component contains all of the serialized fields of its base type, they should be completely compatible with the data from the original.

    One could even take it a step further and allow components to be overridden with any other component, and have any serialized fields that match the base component by name inherit the values; although this would probably not have much practical use.