Health System Implementation - C++ Super Classes


I am trying to implement a generic health system for a game. I created a C++ abstract super class that hold variables and method definitions. I want them to be accessible to the blueprint editor so they can be edited and implemented by BP classes inheriting them.
I created intermediate classes that inherit from this superclass as well as UE4 classes actor, character etc and they can access the variables in the superclass.
But the BP classess inheriting from the intermediate classes has no access to variables or methods.
I have exposed the variables with UPROPERTY(BlueprintReadWrite) and functions with UFUNCTION(BlueprintImpementableEvent). But they still don’t show up in editor.

The superclass is independent of UE4 and does not inherit from any class. I want to use it with different UE4 classes.
The code compiles fine. Is there anyway I can expose it to BP without the superclass inheriting from UE4 objects ( that will defeat its purpose).
I have heard of UINTERFACES but I am not sure if they will hold the variables required for the health system.


You need to use an Actor Component. They exist to fulfil this purpose and also help compartmentalize code and concepts.

You can’t have UPROPERTY variables in interfaces, or non-UCLASS()'s - and you are not able to multi-inherit from more than one UCLASS() at a time.

Thanks for the info. The reasoning behind this is that I have characters and non characters that will use this system. As you mentioned, I cannot inherit from more than once uclass so I would need to duplicate the same definitions in two classes. Is the composition a better apporach for this, the health system instance being a component of actor instead of being a parent class? Thanks

Yeah exactly. You would create an Actor Component that stores the health and functionality you need, then add that component to any actor that needs to have health. Whatever needs to modify the health of something (such as a weapon) would look for that component on the actors it’s effecting and interact with it accordingly.

If you want to avoid searching through an actors components to find the right one, you can create an interface for actors, and provide a function to return a UHealthComponent* - then you can enforce certain actor classes to provide that component. If the interface is inherited natively, you can also cast to the interface directly so you get direct access.