Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question [SerializeReference] in NetworkBehavior?

Discussion in 'Netcode for GameObjects' started by doodlinbee, Feb 19, 2024.

  1. doodlinbee


    Feb 15, 2020
    I have an abstract "Effect" class, on my MonoBehaviors I can simply do
    Code (CSharp):
    1. [SerializeReference]
    2. 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?
  2. CodeSmile


    Apr 10, 2014
    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.
    doodlinbee likes this.
  3. spiney199


    Feb 11, 2021
    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.
    doodlinbee likes this.