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
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
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 (: