# Call function on all actors

**URL:** <https://forums.unrealengine.com/t/call-function-on-all-actors/308667>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 2, 2015, 2:00am UTC](https://forums.unrealengine.com/t/call-function-on-all-actors/308667 "2015-03-02T02:00:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wrekk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wrekk](https://forums.unrealengine.com/u/Wrekk)\
**Post date:** [March 2, 2015, 2:00am UTC](https://forums.unrealengine.com/t/call-function-on-all-actors/308667/1 "2015-03-02T02:00:42Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [March 2, 2015, 4:34am UTC](https://forums.unrealengine.com/t/call-function-on-all-actors/308667/2 "2015-03-02T04:34:46Z")

</div>

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:

> **[IMessageBus](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Messaging/IMessageBus/)**
>
> Interface for message buses.

> 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](https://wiki.unrealengine.com/Interfaces_in_C%2B%2B)

---

<div class="post-metadata">

**Author:** ![Wrekk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wrekk](https://forums.unrealengine.com/u/Wrekk)\
**Post date:** [March 2, 2015, 1:47pm UTC](https://forums.unrealengine.com/t/call-function-on-all-actors/308667/3 "2015-03-02T13:47:48Z")

</div>

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!
