How to wait for a Blueprint Delegate execution to be completed

I have two DYNAMIC_MULTICAST_DELEGATEs that must be broadcasted one after another in C++.


firstDelegate.Broadcast();

//firstDelegate has been fully executed
secondDelegate.Broadcast();


They can be assigned via BP therefore including latent functions that can span multiple frames.

What’s the best way to deal with this in a thread-safe way?

How can I detect when a delegate is fully executed without assuming anything about what it’s bound to it?

I’m not sure if any of those Async tasks can be of any help, I cannot find an in deep documentation for them

Design your latent nodes to support callback events.

Thanks but it’s not what I want. I want to use any kind of latent node and I want them to be anywhere in the node chain.

It sound more like a design problem. There’s no such thing as a broadcast “being fully executed” because latent functions being called by the delegate’s broadcast method do not block it from returning. If you look at how a latent function works, you’ll see that it’s just a syntactic sugar for hooking up delegates. The delay node, for example, basically creates a timer that will fire a delegate that executes the node’s “then” pin after the specified time has passed. It’s not part of the execution stack.

It sounds like firstDelegate fires off a bunch of “jobs”, which may or may not be asynchronous, and when all jobs are completed you want secondDelegate to be fired. You need:

  • A way to track how many jobs where started
  • A way for each “job” to report back when it’s completed
  • Fire secondDelegate when all jobs are completed

You could create a “JobTracker” object that stores a “PendingJobCounter” int variable, has a “OnAllJobsCompleted” delegate and a “JobComplete” method. You initialize PendingJobCounter with the number of subscribers in firstDelegate, subscribe to “OnAllJobsCompleted” (so you fire secondDelegate when it’s fired), and pass the JobTracer to firstDelegate as a parameter. Each listener is required to call “JobComplete” on the received object once to report back. What “JobComplete” does is decrement “PendingJobCounter” and, when it hits zero, fire “OnAllJobsCompleted”, which will then fire secondDelegate. Optionally you could also set a timer when firing firstDelegate that prints an error message if the jobs didn’t complete after some time, so you can be alerted if someone forgets to call JobComplete somewhere.