Search Unity

Can't override type of SerializeReference fields in prefab instances

Discussion in '2019.3 Beta' started by menderbug, Nov 12, 2019.

  1. menderbug

    menderbug

    Joined:
    May 14, 2018
    Posts:
    26
    I ran into another issue with
    [SerializeReference]
    . If I have such a field on a component that's used in a prefab, and I then change the type inside the that field to something else in a prefab instance (either as part of another prefab, or in the scene itself), the new type doesn't actually get saved. I think this is because Unity's serialisation format doesn't actually have a way to specify type overrides yet.

    Is this a known issue? Are there any known workarounds?

    With all these teething issues, I'm probably going to go back to
    [SerializeField]
    ,
    ISerializationCallbackReceiver
    and type-indicating enums for now. The new feature to serialise references is really powerful, but doesn't quite feel like a first-class citizen in Unity just yet.
     
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,492
    Not a known issue AFAIK. Could you please submit a bug report?
     
  3. menderbug

    menderbug

    Joined:
    May 14, 2018
    Posts:
    26
    Sorry, took me a few days to make a separate Unity project for this, but I've submitted a bug report now (case 1199395).
     
    LeonhardP likes this.
  4. menderbug

    menderbug

    Joined:
    May 14, 2018
    Posts:
    26
  5. menderbug

    menderbug

    Joined:
    May 14, 2018
    Posts:
    26
    @LeonhardP can you say if there are any plans to include a default property renderer for [SerializedReference] fields? (I'm imagining something that just gives you a dropdown for all types derived from field's type and then just uses the normal property rendering for the actual value.)
     
  6. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,492
    Thanks for the bug report! I've relayed your question to the devs.
     
    menderbug likes this.
  7. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,492
    Got two replies from the devs.

    Re: default property renderer, there are no plans at the moment.

    Re: overriding type in a prefab instance,
    unfortunately this isn't possible due to how prefab instances store modifications (path/value). It's a known limitation but is currently undocumented. We'll include a note in the docs.
     
  8. menderbug

    menderbug

    Joined:
    May 14, 2018
    Posts:
    26
    Thanks for the quick response. That's unfortunate. The lack of a default renderer isn't a huge issue, since it's not too hard to write one yourself, but not being able to actually change the type of a field is a pretty big deal breaker for a feature that's supposed to enable polymorphic serialisation.
     
    kyuskoj likes this.
  9. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    414
    Prefab variant fields are resetted too from my testing.
    Do that limitation applies to prefab variants?
     
  10. menderbug

    menderbug

    Joined:
    May 14, 2018
    Posts:
    26
    I'm pretty sure it does, since it's just a fundamental limitation of Unity's current serialisation format.
     
    TextusGames likes this.
unityunity