Changing inspector default values from subclass OR hide from inspector in subclass only.

I want to subclass “Weapon” as a “Cannon” and set some default values in the Cannon class such as fire rate, damage, and so on. I want to be able to add a Cannon to a GameObject and have it use the Cannon’s default values in the inspector, not the generic Weapon’s values. Per this post, I understand that this is not possible…

As a second best alternative, is there any way to hide those values in the inspector if it is a Cannon, but have them still accessible if it is a weapon.

I want to do this because if I am setting values in the Start() function of the Cannon (seems to be the best option), the values in the inspector are useless and only serve to confuse the developer. I still want the concrete Weapon class usable as is though for testing and playing.

Thanks!

Yes you can…

class BaseClass : MonoBehaviour
{
    public int someValue = 5;
}

class SubClass : BaseClass
{
    public SubClass()
	{
		someValue = 10;
	}
}

You should use the Reset function for this. The constructor can be called multiple times (at each deserialization) and all serialized values get overwritten with the stored values.

class BaseClass : MonoBehaviour
{
    public int someValue = 5;
}


class SubClass : BaseClass
{
    public void Reset()
    {
       someValue = 10;
    }
}