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?
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.
I’ll take a look, thanks.
EDIT: Any chance you could give me an example of how to use the message bus?
EDIT2: Tried interfaces and it works really well, thank you!