noob question - Blueprint Interface

I was watching the Twin Stick Shooter video tutorial on the Unreal channel, and I’m kind of confused by the Blueprint Interface…
For what I’ve understood,Blueprint Interface is like a bridge that allows multiple blueprint to communicate and affect each other. Thing is,if I got it right,in the videotutorial example the Blueprint Interface “iDamageable” is called by the projectile to damage the Enemy,and is also called by the Enemy to damage the player…but all that “iDamageable” has is a single float variable,so if the projectile hit the enemy while the enemy hit the player (both happen simultaneously)…isn’t that thing bound to fail? I mean how does it works?!

Or let’s say that the Enemy call the “iDamageable” BP Interface in order to damage the player, since the EnemyBP also takes the input from that interface in order to get damaged,shouldn’t that damage value he sent come back to damage him?! Or the way Blueprint Interface works is specifically programmed to avoid this?

I’m very confused :\

I would start off with this: Blueprint Interface | Unreal Engine Documentation which is the official documentation. Then this: - YouTube official youtube video. Then think about the Flamethrower example that gets thrown around…

Basically… Flamethrower spits out fire… but not everything that it touches will burn… so a BPI will be made called something like BPI_Burnable and anything that needs to be burned will implement that interface. Then in each BP that needs to burn, will have an event called once Flamethrower fire reacts to it. Event Takes Fire → BurnMe.

Trust me, I found casting/BPIs/BP communications a huge mystery as well, but after looking through everything and going through examples, it just clicked.

I hope that helped.

@Victor : saw both,but unfortunatelly I still have the same doubts from my first reply :\

i’m no expert, but that you think an interface “has” a float variable sounds wrong to me. an interface is only a collection of functions without implementations. the actual health data would have to be stored in a blueprint that implements the interface.

Ok, lets start more basic.

You know what a Function or CustomEvent is? Let’s stick to the CustomEvents.
In a specific Blueprint, you can add them (as well as Functions) to do some stuff multiple times without rewriting the logic.
This is the basic logic behind them. So if you have some complex calculation that takes 50 nodes, you may want to use a CustomEvent or Function.
You can just reuse them.

ALSO, you can call these CustomEvents and Functions from outside. To do this, you need an actual reference to the spawned actor (or created UObjects, but
let’s keep it to actors). In the Video shared above by Victor, the LineTrace is getting this.
BUT, when doing it like this, you need to make sure that the actor you got is of exactly that Blueprint or at least a Child of it.
How do we do that? Simply by casting the HitActor to the Class. This cast fails if the Actor is not of that class. So if the Cast succeeds, we know that
we have hit an actor of that specific class and now we can call the function.

Seems pretty straight forward, doesn’t it? (:

NOW, imagine you want to implement things that should happen when your Trace hits an actor, but each actor should react differently.
If you would use the method above, you would need to create an Event in each actor (which is not much different) AND try to cast the HitActor
to each and every possible Blueprint Class. Imagine you have 10 Actor that should all react to the right click trace and they don’t share the same
class. Then you would do 10 casts and call a CustomEvent on each for the case the cast succeeds.

How to solve this? Simple, by using an Interface. You create the Event (only the declaration, not the implementation!) in this BlueprintInterface
and add it to everyone of these 10 actors. Now, when you hit an Actor with the line trace, you don’t need to cast. You just call the InterfaceMessage.
It will deal with the different classes. Once a HitActor has an Impementation of this interface, it will call it. So you reduce the 10 casts to one
simple InterfaceMessageCall.

For your question with the bullets: The Events are not linked to each other. Each actor deals with the call on its own. If the bullet calls the interface event
on the enemy, it will deal damage to him by calling the event inside of the EnemyBlueprint, based on the implementation of the Interface.
If in the same time the enemy attacks the player, the player version of the Interface will be called to damage the player. They aren’t linked.
But for a single thing like this, you could also just use the “ApplyDamage” function of the base AActor class. You don’t need an Interface for that exact
thing.

And the questions with the damage coming back to the enemy: No, it won’t. You need to give the Call a reference to an actor. When the Enemy attacks
the player, he will call the Interface Message on the PlayerActor. The Enemy will not get the call unless you do that somewhere (: