Inspector default values on derived Scriptable Object Class

Hello, I have found that the default values won’t be initialized when creating scriptable object from right click, if it is from a derived scriptable object base class.

abstract public class StatusEffect : ScriptableObject
{
    [Header("Generic Fields")]
    public string statusEffectName = "Test"; //This will result in blank inspector default values.
    public string description;
}

public class SpeedBoostEffect : StatusEffect
{
    [Header("Speed Up Fields")]
    public float baseMSBonus = 2; //This will result in blank inspector default values.
    public float multiplierMSBonus = 0.2f; //This will result in blank inspector default values.
}

Why wouldn’t the default values work like regular fields?

Thank you.

May be .net serializer overrides them or do not call base class field initializers at all. Declare a parameterless constructor and initialize defaults explicitly in constructor.

You could add a Reset() method to the derived scriptable object and assign the default values there.

8 Likes

Reset() is better place to set defaults than constructor for consistency since reset also will be called when reset menu item is clicked.

3 Likes

This works so well, thanks!

Excellent, Reset() was exactly what I was looking for, many thanks!