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"

[Closed] Are delegates blocking or asynchronous?

Very basic question, as the title suggests: when I subscribe to a delegate via AddDynamic() and then call Broadcast() on it, does it process the event in a blocking fashion, or is it asynchronous?

Example:

 DelegatesComponent->SquadLeaderChanged.AddDynamic(this, &USquadMembershipComponent::OnSquadLeaderChanged);
 DelegatesComponent->SquadLeaderChanged.Broadcast(Squad->SquadLeader);

 // IS THIS GUARANTEED TO EXECUTE ONLY AFTER OnSquadLeaderChanged HAS FINISHED?
 Something();

 void USquadMembershipComponent::OnSquadLeaderChanged(AActor* SquadLeader)
 {
     bSquadLeader = GetOwner() == SquadLeader;
 }

So does Something() execute only after OnSquadLeaderChanged() has finished, or is another thread listening via Broadcast()?

I couldn't really find anything in the source code.

Product Version: UE 4.18
Tags:
more ▼

asked Jan 23 '18 at 03:06 PM in C++ Programming

avatar image

GlassBeaver
133 7 16 16

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

The question has been closed Nov 02 '18 at 11:22 PM by GlassBeaver for the following reason:

The question is answered, right answer was accepted


1 answer: sort voted first

The implementation of delegates is very complicated and is completed by UHT at compile-time. It looks like the event is sent to the registered UObject synchronously. I can't tell you 100% if it is complete synchronous, but it looks like that.

I also use delegates and didn't run into async problems, the always fire at the right time.

more ▼

answered Jan 23 '18 at 04:07 PM

avatar image

birdfreeyahoo
885 47 46 80

avatar image GlassBeaver Jan 23 '18 at 04:21 PM

Thanks and yeah, that's also been my experience so far. Just wanted someone with more insight to confirm if it is guaranteed to be the case. I guess if I don't get a dev to answer then I'll just mark this as accepted in a couple of days.

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

Follow this question

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

Answers to this question