Download

Is it possible to call an event on an actor derived class without knowing the class?

I’ve got an actor derived blueprint class with an Event on called “Pinged”. Now I want to call that Pinged event on the class when my “Ping” class overlaps it. Works fine if I do an overlap check and check a tag on the actors returned and then Cast that to a specific class type and then get the event to call.

But how do I do it so that ANY actor can be pinged in such a way that I don’t have to cast it to a specific type?

In general what I’m thinking of is a message system where you don’t need to know the type of the receiver. So I want to call an event on any actor that actually implements that event. Is there a way to do that?

Ta.

short answer, use blueprint interface, and only implement to those you want to have a response. if there is a lot those class, first implement a parent class, inherit it, so every subclass also has the same call.

How do you create a blueprint “interface”? Is that some specific type of blueprint? Are we talking interfaces like C# style interfaces? How do you test if an actor has the interface? Anywhere there’s more info on this stuff? sounds like what I want.

Ta.

The Blueprint Communication level in the Content Examples project has a couple of examples of Blueprint interface uses. The interface itself is actually an asset you create in the content browser (under “Miscellaneous”), and you open that up to add functions to it. This should hopefully explain the rest: Blueprint Interface | Unreal Engine Documentation

In order for a Blueprint to be able to receive interface messages, you need to go into “Blueprint props” at the top of the Blueprint editor and assign your interface asset there. Then if you want to check if a particular Blueprint uses that interface you can use the “Does implement interface” function with the Blueprint in question as the target. So if you use an interface function for causing damage to enemies, for example, the “Does implement interface” check could be a useful way to determine if the actor a projectile is hitting is an enemy or not without needing to cast to a specific class.

Ah nice… turns out that is exactly what I wanted. Thanks.

For others looking at the same thing:

I also touch on this a bit here: