Search Unity

Prefab variant inheriting source values with extended script replacing a component.

Discussion in 'Prefabs' started by QuantumCalzone, Sep 16, 2018.

  1. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    Is there a way to create a prefab variant and replace a component with an extended version of itself without breaking the connection?

    Right now you can delete the original component on the variant and add the extended version (at the bottom since re-ordering components also breaks the prefab link), but it would be nice to have the shared values between the source prefab's inherited component where no deviations designated in the inspector.
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    I just tried changing the 'Script' field (with the inspector in debug mode)
    I got a
    error.

    you can try to avoid inheritance and refactor the 'derived' script to a separate MonoBehaviour with [RequireComponent()]
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    My impression is that this is not possible. I however don't have an overview of the approach of switching the script reference as described by M_R, which logs an error. We'll look into this.