Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Request: override component with derived component in variant

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

  1. p-lindberg


    Feb 19, 2019

    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.