Call function on all actors

Hello.

How do I call a function on all actors in an array?

In Unity you could do gameObject.SendMessage ("ApplyDamage");, which would call all functions named “ApplyDamage” on the scripts the actor “gameObject” has attached to it.

I have an actor class with a function I’d like to call without casting to it first (cause I’ll have multiple classes with a function named the same thing later on).

Any ideas how I should tackle this one? :slight_smile:

UE4 has it’s own message bus implementation if you interested, it’s has the longest description i ever seen yet in API reference so it should be good starting point:

I have an actor class with a function
I’d like to call without casting to it
first (cause I’ll have multiple
classes with a function named the same
thing later on).

If you want to relate unrelated classes, you can use inteface. C++ does not formally support interfaces, instead it support multiple class inheritance which let you do similar thing, UE4 reflection system won’t let use multiple inheritance itself inside UObject class tree, but it utilizes that feature to emulate interfaces.

https://wiki.unrealengine.com/Interfaces_in_C%2B%2B

I’ll take a look, thanks. :slight_smile:

EDIT: Any chance you could give me an example of how to use the message bus? :slight_smile:

EDIT2: Tried interfaces and it works really well, thank you!