UE4 Health system Blueprint interface system messing up

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.

Yes, you can. I just provided you with an example of inheritance above. I don’t actually know how to even properly respond to that. Why not? What do you even mean by that? Inheritance is at the very core of OOP. You can’t really get far without it. If you’re casting, you’re already using inheritance…

Obviously, a weapon should not inherit from a character because that’d make little sense - both inherit from Actor, naturally. And that’s precisely why you’d use an interface. Connect 2 (or more) classes that share nothing, and with no casting to boot!

And if you could, when using inheritance, the need to use interfaces is completely meaningless,

No. Just no. What is making you say that? If you have 2 unrelated classes (character & weapon, and their respective children) that know nothing about one another, you can connect them with an Interface. Now any child of Character can talk to any child of Weapon. Same for for both base classes.

since you only need to cast the parent actor of both

If you cast to the parent, you cannot talk to the child… so, no, you’re incorrect.

To me it all sounds a bit as you’ve been avoiding interfaces and relying on other, less efficient and more convoluted means of communication and now that your mind is set, there’s no going back.

In the end, I’m not here to convince anybody but to clarify. Yes, interfaces make perfect sense and if you want a character to talk to a weapon, it’s pretty good case scenario. Effortless and no casting is required.

@ DanielG1939 Apologies for hijacking your thread.

I haven’t really used interfaces much so I can’t comment on that but…
I just built a system like this today using a master “Stat System” component that i can tack on to any player or NPC. Then there is a “Buff” component with corresponding values and an apply buff function that takes a Stat System as an input and then copies itself as a child of whatever owns that stat system so i have a history of all the buffs applied to that character. I add the Buff component to a master “Pickup” actor class that calls the apply buff function on overlap and deletes itself. Works for health packs, attack or defense stats, or any combination of any stat within the Stat System. The stat system itself calls a “die” function in the corresponding default player class or NPC class i’ve created and handles application of damage internally.

Update: started implementing interfaces and they are indeed useful. Use an interface call to get the “Stat System” component from either a NPC or player without casting and it significantly reduced the number of nodes i need for my weapons damage state system. Gonna get around to implementing interface calls into my custom team sense service too. Gotta say, interfaces + components is a powerful combo.

1 Like