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"

Performance of Multicast Delegates and their Ordering in Comparison to an Array of Delegates

Under the hood, are multicast delegates implemented using contiguous memory to store the delegates or are they implemented using Linked List like structure?

It does not specific in the Unreal Documentation, but is the order in which delegates are added to the multi-cast delegate always guaranteed? Or are they randomly fired off regardless of their original order in which they were added to the multicast delegate.

What would be the advantages of multicast delegates over just a TArray of delegates where order is assured as well as the fact that would be stored in contiguous memory?

Product Version: UE 4.9
more ▼

asked Dec 14 '15 at 01:55 AM in C++ Programming

avatar image

6 2 3 6

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

1 answer: sort voted first

The invocation list is an array of delegate instances.

The order of invocation is not guaranteed by the contract. Technically, the order depends on when delegates are inserted or removed. However, you should not rely on that, because we may change the internal implementation details in the future.

If you maintain your own array of delegates, then you would be in full control of the order of execution. That being said, such a design would also not be advisable, because it will temporarily couple the delegate handlers to each other. You should design your code in such a way that each handler can successfully execute regardless of whether and when any other handlers execute. The handlers should not have to know about each other's existence. Otherwise you're asking for subtle and very difficult to find bugs down the road.

more ▼

answered Dec 14 '15 at 07:05 AM

avatar image Nuclear-Cheese Dec 14 '15 at 09:05 PM

Thank you! This is exactly what I wanted to know.

On the subject of delegate coupling, is it therefore inadvisable to "daisy chain" delegates or events together. i.e

PlayerInput triggers ->

UTriggerComponent OnTriggerPulled which then triggers ->

BFiringComponent OnWeaponFire- which then triggers ->

Both UPatricleEmitter, UAudioComponent's respective delegates (these last two would be in no particular order)

OnTriggerPulled, OnWeaponfired are now coupled by order (OnWeaponFired must come after OnTriggerPulled

But OnTriggerPulled is not the only Component which can trigger OnWeaponFired

I wanted to decouple the components of a TriggerComponent and a FiringComponent since an actor may have only one of those. (In FiringComponent's case their would be other possible Components that could cause it's delegate to fireoff)

Is this advisable or is this a no-no?

avatar image gmpreussner STAFF Dec 14 '15 at 10:17 PM

It is OK for the UTriggerComponent to trigger an event on BFiringComponent. What I meant about delegate coupling is that the delegates registered inside the same multicast delegate should not depend on each other, i.e. all handlers of a particular multicast delegate should be independent from each other.

I think I understand now what you mean to accomplish by having an array of delegates. It is not really a delegate that broadcast an event pseudo-simultaneously, but a way to structure the order of execution of multiple functions. I think that is OK if you can make this apparent from your API, so that there is no misunderstanding.

(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