[SerializeReference] in NetworkBehavior?

I have an abstract “Effect” class, on my MonoBehaviors I can simply do

[SerializeReference]
public Effect effect

That enables me to have a dropdown list in the inspector with all the effects that inherits this class.

I tried to do the same thing inside a NetworkBehavior but I can’t see a dropdown in the inspector. Is there a solution to this?

Can you replicate this in an empty MonoBehaviour and then changing its parent class to NetworkBehaviour?

If the Inspector field vanishes when you change the parent class this is likely caused by a custom editor script for NetworkBehaviour types. You could search for it and try to adapt it, or make your own editor script for the particular implementation type where you need to see the effect.

Then there’s the question why the effect class needs to be abstract? There’s usually other (data-driven) ways to make variants other than base classes or interfaces. Or simply don’t make the base class abstract. As long as you remember never to instantiate EffectBase it’ll be fine.

1 Like

NetworkBehaviour has a custom inspector that overrides the default inspector (and seems to do absolutely nothing of note) which causes inspector tools not to work for it.

You can write an empty Editor class for your type which should Unity control over it. You may need to draw the default inspector too.

If you’re using Odin, do the same with with an empty OdinEditor class.

1 Like