How do I add a delay to each iteration of a foreachloop?

Brilliant solution! As long as people remember to create a new macro and not edit the standard ForLoop one!

Oh, thanks, really useful!! :smiley:

I created two new macros called “For Each Loop With Delay” and “For Loop With Delay”

The Macros can be downloaded here:

Key thing was that the Macro library had to be based off of “Actor” and not “Object” as you cannot add a Delay node to Object Macros.

This means that if you want these nodes in your UMG or Animation Blueprints you will need to create local macros or derive the macro from another source than actor.

Here is the “For Loop With Delay” Logic:

Here is the “For Each Loop With Delay” Logic:

5 Likes

Genius! Thanks, mate!

You can use “set timer by event” for less messy graph

usable only on main graph tho

Another way is to put everything you want to do in an event, and put in a delay node there, passing on a ‘delay’ float and any other parameters you need.

This way you also have control over the delay per loop step, ie you can do any stuff with index before you pass it to delay input, or not to do it immediately. (not just delay * index)

This looks complicated haha I dunno if the engine had major revisions since the time this post started regarding this macro BUT as of 4.18 it is super simple.

  1. Create your own custom macro using the blueprint macro library
  2. Copy all the features of the “for each loop” or “for each loop with break” whatever you want to add a delay to
  3. Add 1 extra input (float) to be used as the delay
  4. Add a delay node following the “Assign” that loops back to the branch node
  5. Hook the input float into this delay

Here is a tutorial showing how to do this for those of you who prefer that instead.

Simple and now you have a custom “Loop with Delay” that you can set when calling the macro itself.

5 Likes

Perfect! Thanks

Made my day

Thank you very much Miroac! That worked like a charm and exactly what I was looking for to do. Cheers!

This is indeed the solution! Thank you!
I’ve modified it a bit so that the delay sits inside the macro. Now I use it like my other modified macro: While Loop with Delay. Which is basically a simple timer. I wish Epic would add these to default macros in Unreal, they’re very useful.

1 Like

Of course it is possible. The image above shows exactly that.

How can you have delay inside of a macro? I don’t think it’s possible

Are you sure it’s a Macro, not a Function? I don’t see Delay in the select, and it’s been reported many times that it doesn’t work. So I’m just wondering how you did it. Delay and other latent actions inside a Macro - Blueprint Visual Scripting - Unreal Engine Forums

Yes, you can add delays inside Macros. You cannot add delays inside Functions.

this is only possible in actor macro, not in macro library

Ah I see, so that’s the difference, I was trying to make a new modified library. Thank you!

So almost a "Do N" with a ‘completed’ out.

Thank you!