I have a bunch of scripts that inherit from one and other, the following is an example:
Food is base class,
meat and fruit which inherit from food
Apple and orange which inherit from fruit
If I make a list of food, and only add food types to it, then it functions as expected.
[SerializeField] List<Food> food = new List<Food>(); // copy paste functionality works if i just add food types
[SerializeReference]
[SerializeField] List<Food> food = new List<Food>();// cant copy paste from this list
Problem: if I add inherited members to food list with attribute [SerializeReference] on the list, I no longer have the copy paste option when I right click on the element in the inspector. I only access to duplicate and delete.
How can I regain this functionality while retaining the [SerializeReference] to display all inherited members in a list?
Probably a limitation of Unity’s collection drawer. Unfortunately we cannot write property drawers for collections, so you’d be limited to using a custom UnityEditor.Editor
and manually drawing the collection and handling any contextual menu stuff yourself; would just be overkill.
Also don’t use both [SerializeField]
and [SerializeReference]
. Only use one or the other; you don’t need both.
That said Unity doesn’t support adding/removing types serialized with SerializeReference by default without some custom inspector work. So do you already have a custom inspector at play here? Or potentially using Odin Inspector?
I am creating an asset for the asset store, So I can’t use Odin - Otherwise I use it for my own personal projects and this is a pain without it lol
I have created a custom inspector already, yes. I could make a copy past button in there as I already have the attribute set up to do that, but It seems a little clunky. Thanks for replying.