What is the best way to create a health system?

This is usually done using interfaces.

Interface methods must be overridden (implemented) in all objects that inherit the interface so you can access all needed functions while implementing the interface in the objects.

Hi, I want to make a basic health system in my project. In this system I want to be able to damage barrels (Actors), robots (Pawn) and Humans (Characters). Now I would like to have just one damage function and one health variable I have to access.


First I tried just to make a parent child system. But the problem is, that if I inherit from AActor, I can’t use any Pawn and character classes. If I inherit from APawn or ACharacter, I can’t use the base AActor class anymore.


I could rewrite the AActor class, but I don’t think that is a good idea, because all other classes use these codes. Plus my engine breaks when I try that.


Next I tried to make the functions in the controller. But first, actors don’t have any AiControllers and second you would have to rewrite the function in the player controller.


My last idea were interfaces, but in the interfaces I can’t set any timers (like the time delation from dispawning after the Actor dies. Plus I can’t access GerWorld(), because that’s an AActor function and not Interface. So I can’t cast to the MainPlayerController.


With this I don’t know any other easy ways to create a health system. Thx for the help!

Thx for the answer. As I said in my question, I can’t access “GetWorld()” in my I-Interface part of the class. So do I have to override every function in the implemented class to set timers or is there an other way?

Yes. The project will not compile if the interface functions are not overridden in the class implementing the interface. This means that when you implement it in the AActor you will have access to GerWorld().

Keep in mind that you can implement a function with empty body in any calss.

You can check the wiki and the official documentation if you are unsure on how to implement interfaces.

Thanks for the answer. I think I will be alright now.