Search Unity

Prefab variants and monobehaviour inheritance

Discussion in 'Prefabs' started by Tomer-Barkan, Nov 19, 2018.

  1. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    This could be useful:

    I have a parent prefab, and it has a monobehaviour attached to it with all the needed references.

    Now I want to create a variant of this prefab, that adds new parts to the prefab. I also create a child class of the monobehaviour, that adds references to some of these new objects.

    It would be awesome if the improved prefab workflow would allow the prefab variant to replace the parent's monobehaviour with the child one, and keep all the references. Then if I change the parent monobehaviour and parent prefab, including references, those changes will be applied to all variants of the prefab without having to assign the references one by one in every variant.
     
  2. DanielBatoff

    DanielBatoff

    Joined:
    Jan 31, 2017
    Posts:
    2
    Was this sort of feature ever implemented? I've run into the exact same situation, and I can't find a clean solution.

    If this isn't available, what would the best method of implementing a workaround to this problem?
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    It was never implemented. The UI support is there (ish) - when you go into debug mode, you can replace one script with another. It even keeps all the values for fields that have the same names, so this works great for subclasses.

    This does fails in interesting and strange ways when you try to do it to a prefab instance, though, so it wasn't implemented there.
     
    AnomalusUndrdog likes this.
  4. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    This is one of the reasons I'm queasy with relying on class inheritance for specializing/customizing behaviour (composition over inheritance). Still, I can't deny this would be a useful tool to have.
     
  5. Patoto64

    Patoto64

    Joined:
    Jan 11, 2020
    Posts:
    3
    I also need this feature, it's very annoying and bug-prone having to re-assign references in an inherited script component. Placing my vote here for the prioritization of this feature.
     
  6. zORg_alex

    zORg_alex

    Joined:
    Mar 12, 2014
    Posts:
    20
    Same here. I realized that when I change monobehaviour and leave prefab, it doesn't persist when I get back. I'd like this feature.