x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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? :)

Product Version: Not Selected
Tags:
more ▼

asked Mar 02 '15 at 02:00 AM in C++ Programming

avatar image

Wrekk
82 24 24 31

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

https://docs.unrealengine.com/latest/INT/API/Runtime/Messaging/IMessageBus/index.html

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

more ▼

answered Mar 02 '15 at 04:34 AM

avatar image

Shadowriver
37.8k 937 172 1123

avatar image Wrekk Mar 02 '15 at 01:47 PM

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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question