Search code examples
unity-game-engineextendinginspectorscriptable-object

Unity scriptable object only serializing the unity objects


I am trying to make a spell system. My base class for the system looks like this:

public abstract class MagicBook : ScriptableObject {
   public Sprite bookSprite;
   public float manaCost;
   public float coolDown;
   public bool rapidFire;

   [HideInInspector] public bool coolDownElapsed;

   public virtual void OnActivate() {

   }

   public virtual void OnActivate(Vector3 position, Quaternion rotation) {
    
   }
}

Then I have another class extending from MagicBook where I override the OnActivate function. My problem now is that in the inspector only the variable bookSprite is showing and all the other values are not there. I tried adding an [SerializeField] in front of the variables and define them new in the extending class. But they still dont show. Has anyone an idea why they are not showing or how I can fix this?

Thanks for your help and time.


Solution

  • Did you create Asset for ScriptableObject?
    Add attribute to extended class:

    [CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/NewBook", order = 1)]
    

    And then create asset with create asset

    Another idea: Probably you have custom drawer for this object, but... Turn your inspector into debug mode and check if properties are visible there. debug mode

    Cannot reproduce this issue with Unity 2020.1.0f1.

    public class NewBook : MagicBook
    {
    }
    

    Proof