Override Use method

Just a quick question about the Use method in ActionItem, because it’s a scriptable object if you made a ton of sub classes for each item you have wouldn’t that also mean that over in Unity you would have a drop down menu for every individual item type and only create one of each?

Yes, although if you’re clever, you can reduce the actual number of ActionItem children…
For example: You might have three different health potions:

  • Minor Health Potion: Heals 20 hp.
  • Health Potion: Heals 50 hp.
  • Elixor: Heals character completely.

All of these could be represented by a single HealthPotion class. The class would need two fields:

[SerializeField] float amountToHeal;
[SerializeField] bool isPercentage;

And the CreateAssetItem tag would read:
[CreateAssetItem(fileName = "New Health Potion", menuName = "ActionItem/Health Potion")]

Then in Use, you would heal the character by an absolute value amountToHeal unless isPercentage is checked, in which case you would heal the character by a percent of the character’s maximum health.

Now with this single class, you could create three Scriptable Objects to represent the three potion types.

For each of the types (minor health, health, or elixer) you would need just one Scriptable Object for each of them, as you’re just using a reference to the Scriptable Object to get your action item.

Oh, I almost forgot, this same child class could be used to make a healing spell by setting isStackable to false.

1 Like

Thanks @Brian_Trotter! That makes perfect sense, I really appreciate the detailed explanation!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms