Health/Damage System for Player, Enemy, objects, etc

Hello,

I currently have health/shield/armor variables with values for my enemy character and a system for taking damage as well.

However, I also want the same system for objects, players, and other things. How can I implement the same system by just designating it without recreating the variables and functions all over again?

Basically, using a health/armor/shield system across multiple characters/actors without having to redo stuff like variables and functions, so that if an actor has this blueprint, they have HP, Armor, and shields and can take damage.

Hi there

What you need here is a base class for all your character which will hold all those common variables and functions. You can then create child blueprints for your players and enemeis from this base class and they will all have these properties copied to them which are originally defined in the parent class. In object-oriented terms, this is called inheritance. Take a look at these 2 answers (link1, link2) here where I explain how to use inheritance and concept of a base classes in your game design and within blueprints. You can take this even further using another object-oriented concept called polymorphism. This will allow you to define interface functions in the parent class, with their unique implementation in each child. From there you can use this base class as the argument, pass it around and any these interface function. It will automatically link to the specific child and call the unique implementation in that child. Polymorphism is an advanced topic and can be a bit confusing at first. However, once you understand it, your whole coding and scripting will significantly improve! Take a look at these other 2 answers (link1, link2) here where I explained this concept and how it can be applied in these specific scenarios (You can think of these questions as examples to better understand this concept).

Hope this helps :slight_smile:

~Vizgin

Thank you! I think what you posted is what im looking for and I started to put it into practice.