How to prevent an inherited variable from showing up on a scriptable object?

Okay so I created a scriptable object thats an item, and I then created another srcriptable object class for specifically equipment, which inherited the item class. This (of course) brought over all of the ‘item’ class’es variables, which for now include how much health that item will restore to the player as a float. (“healthHeal”) However, since the equipment class inherits the item class, this means when you create a new equipment peice you can see you still have the option to change how much health it heals. I was wondering if there is a way to prevent specific variables from showing up in this instance, specifically so ‘healthHeal’ isnt shown when you are making a new equipment.
And thoughts?

Here is the item class:

public class Item : ScriptableObject {

new public string name = "New Item";
[TextArea]
public string description = "";
public Sprite icon = null;
public bool isDefaultItem = false;
public float healthHeal = 0f;

public ItemUse useText;

public virtual void Use() //item is used, something might happen.
{
    DamageTextController.CreateDamageText(healthHeal.ToString(), PlayerController.globalPLayerPosition, "Green");
    StatController.playerHealth = StatController.playerHealth + healthHeal;
}

}

Here is the equipment class:

public class Equipment : Item {

public EquipmentSlot equipSlot;
public int armorModifier;
public int damageModifier;

public override void Use()
{

    //Equip the Item
    EquipmentManager.instance.Equip(this);
}

}

public enum EquipmentSlot { Helmet, Chestplate, Boots, Weapon, Charm}

I submit that it is an error to think in terms of hiding variables with the purpose you have in mind. The problem is not that the base class has a “health” parameter that a derived object does not need, it is that the base class itself is polluted with the “health” parameter that should not be there.


This is a typical issue in object design. First, you’ve developed an object that works for a player (that has a need for health). Next, you create a derivative of that object as if it were a base, but it isn’t a base, it’s a player (that needs health). What you’ve demonstrated is a missing class that isn’t there. You should now create a player class, derived from that base class, and MOVE health into THAT class (and anything else that isn’t required by your equipment derivative). In this way you “clean” the base of the pollution that otherwise corrupts its position in your hierarchy as a base (a generic class that does all the things ALL of the derivatives must do - and in this context the term generic means general, not related to the ‘generics’ in C#).


Once you practice this (and you likely will end up in the same situation in the future), you’ll realize it isn’t that the language is missing a technique you’d like to use, but that by reorienting your thinking you’ll realize the technique you require is associated with the concept that form is functional (that where you put code is part of the functional definition of that code). The feature you’re thinking of using isn’t required, just an adjustment of viewpoint.