Download

UE4 Health system Blueprint interface system messing up

Hi, So I’m prototyping a game right now and I’m trying to design a health system using a Blueprint interface that has two functions which is Damage and heal. The reason I’m using a blueprint interface is to hopefully allow for communication of damage between players, breakable objects, weapons, etc. and to allow for user made content to be a little easier to implement, such as custom weapons and such. I’m hoping Blueprint Interfaces are a good way for communication with base game items and user made content. but anyway onto the problem I actually need answered.

I have a Character blueprint and two test objects the player can walk up to and interact with to test the health system. one object damages the player and the other heals the player upon interaction. Now the problem is, is that the objects don’t seem to fire the heal or damage event inside the player blueprint. Now I tested the interaction between the objects to see that when I press the use key and interact with them they actually fire the interaction event, but don’t continue the heal/damage code or even the event inside the player blueprint.

Now I will show the code that I made for the system. I have a blueprint Interface with 2 functions, Heal and Damage. I’m gonna just show the Heal code I have currently instead of just showing both Damage and Heal code since their functions are similar. So for the Blueprint interface Heal function, I have one input and its just the Heal amount and object does.

And next I have the Test healing item, that when interacted with, heals the player. I think its kind of self explanatory what the code is supposed to do.

and next I have a temporary heal system in the player blueprint. Right now I have not made a true death system (just destroying the actor when the health reaches zero.) and a cap for player health, I’m just making a healing and damage systems that show the current health variable number in printed strings. The health variable is an integer by the way.

I know this may seem like reading an entire novel but I really do want to know what I’m doing wrong as I’m still very new to using blueprint interfaces and would like to get a better understanding of them. Thank you for taking the time to read!

Does the player actually implement the interface?

Yes the Player blueprint does have the Interface in its class settings and I’m able to get the heal event in the blueprint. So as far as I know I think it implements the interface? Idk, like I said I’m still not 100% on how to use Interfaces.

If the player implements the interface, all you have to do is get a reference to the player somewhere else ( not in the player ), and call the interface event.

I do have the player referenced in the healing test item and it sends a message to the interface? is that not a way to get a reference to the player and send a message to fire the event?

I also deleted the code in the player blueprint and decided to try and at least start over fresh but it said I couldn’t add the heal event back into the player blueprint since it already exists, despite the fact I deleted it? I had split up the damage and heal functions into separate blueprint interfaces since I couldn’t use the original interface. but the code still doesn’t function, and won’t heal the player. I used the same code as I did in the pictures above but still nothing happens… what am I doing wrong?

Where is that player reference coming from? What is it that damages the player? Is it via overlap events or line trace?

The player reference is just a variable that is a character type that references the player blueprint. The interaction event is a line trace from the player blueprint that fires a Interface message when it hits an actor, then fires an event in the blueprint which is supposed to be the heal event. the health is an integer in the player blueprint and right now the heal system is supposed to add to it and damage subtracts from the integer. the item doesn’t heal when the player overlaps a collision sphere but when the interaction event fires, if that helps explain it?

Well how does it reference the player? Did u just create a variable and set it’s type, then dragged it in blueprints? That’s not how it works in the engine. You need assign a value to that variable cuz right now its null, u can do this in a lot of different ways like overlap events, line trace or whatever it actually depends on ur situation.
But one easy way to access your character is to use get player character node and then cast it to your player blueprint which will give u access to the character. You can also use interfaces instead of casting which is more efficient.

I do have the Variable type set to my Player Character blueprint but I have to assign a value via blueprint? Ok, so can I assign the value in the Healing test object blueprint and if so, what would be an efficient way to assign the value?

Oh never mind I think I got it working! I just put in a set variable type and put a get player character node into the character reference node! Thanks for pointing me in the right direction! I’ll be sure to post again if the system messes up again!

U just defined the variable type. There’s nothing in that variable, its null. U need to read more on how variables are created and used in c++.

Oh, I sent a message back saying I got it working. I figured out how to get the system working from rereading your response above!

1 Like

Actuallly you can skip the “does implement interface”,

and if what you want is to use a mechanism through different actors, also can use components.

One can call interface functions on just an Actor. The whole point here is inter-class comms without casting, ever.

Combine it with inheritance and you’ll never look back at the tight direct comms. At this point your opinion is borderline misinformation, ha. You’re simply not using it correctly.


Judging by the colour of the pins on your node, you’re attempting to call the wrong thing to start with. You’re not calling interface function. You’re calling local implementation. As in:


More info here in the Calling Interface Functions on Other Blueprints section:

LOL, I think it exceeds the border :joy:, currently I tried this several years ago and since then I have completely discarded the interfaces.
I still find them over-engineered in many situations, many times I buy things in the marketplace and see interfaces that only have one or two functions that end up calling an actor.

They are subtle, no doubting it…

Yes, for example this is a clear case, use an interface for life system, I can be wrong again, but you will not have to repeat the same code, por example, the life variable in each different actor? or if you die the logic of dying, how to hide delay and then destroy yourself by making a noise? or if you want to send a dispacher that you have died to the gamemode?
That with a component you would have all that. Without having to repeat anything including delays, macros, or dispacher.

Components are not a replacement for Interfaces. Components provide extra reusable functionality and are really good at that, too. Components also support both inheritance and can implement interfaces.

but you will not have to repeat the same code

You will not need to repeat anything; base actor implements an interface, shared variables and functionality. Children override it as they see fit. You call an Interface Function on an actor and if the child of the base class happens to implement a function for that, that function will be called. And you can optionally call parent’s version, too.

You combine inheritance with interfaces and top it up with actor components where & when it makes sense. For as long as it’s clear in your head and the solution is working, you’re golden. There are scenarios where Interfaces shine.

There will be situations where Interface are not necessary - when classes are known or you’re working within the same class. Or when you’re using direct comms.

If the goal is to avoid casting and make several completely unrelated (or related) classes to talk to each other, Interfaces provide the means for very clear and effortless communication.


For a child inheriting an interface, you can:

Write your stuff in the parent once, children get to call that and then add something extra for themselves (perhaps they have an actor component that parents don’t).

You can execute the above without casting once.

You cannot do common inheritance of charaters (player and enemies) and actors (items and weapons) in blueprints.
And if you could, when using inheritance, the need to use interfaces is completely meaningless, since you only need to cast the parent actor of both, which has the events and the varibles.