Download

How to best do loops with delay in 4.7?

So now that delays are killed off in the standard library in 4.7, how would one best approach this? I really just want the same functionality, a while loop with a delay that I can call easily.

Is my best bet to just create that as a function inside the delay-loop-needed blueprint? Seems hacky.

Thanks!

They got rid of delay nodes?

Not sure while loops are what you want. A tick might be more appropriate. Put a gate or something in there andaybe use delta seconds to time your delay.

What changed in 4.7 exactly? My loops w/ delay are still working. Although the way I had it set up, the delay was outside of the loop macro.

You can also create a custom macro of how a loop works and put a delay into it, or even add an extra input to allow you to set a delay from the outside of the macro.

Here’s my setup for a for loop with delay (and break). It’s pretty simply cobbled together, but it serves its purpose.

5db1b55841a85a1a870679e6eb2bc2eb52f896ed.png

07adf1a60855965fa9a22b03211fa2095b69536f.png

Oh I’m going to unashamedly steal that idea! Great, thanks.

So delays aren’t allowed in the standard macro library anymore in 4.7 hence me asking. With this solution it doesn’t seem to be a problem to be honest. :slight_smile:

Awesome! Glad to help!

Actually it’s still possible to have a loop with a delay inside, you just have to bypass the editor checks by putting the delay in a collapsed graph and than pasting this into the macro.

Rudy Triplett from Epic came up with this workaround, since I asked about it on the answerhub. Just scroll down and you see Rudy’s solution :slight_smile:

https://answers.unrealengine.com/questions/158547/47-preview-3-delay-not-available-in-standard-macro.html

You just need to add a delay node inside the forloop :
Capture.JPG

Using the Loop with delay creates a semblance of asynchrony?
And there is a similarity “StartCoroutine” in Unity to create async operation?
Or just Loop with delay?

Cool! Did not know about this.

I stopped using delays few months back, they are tricky beast, you need to know where you can use them.
Instead i do simple trick:

Remember "delay started at " time in variable. For this i use game time seconds, because it adjusts with pause and slow down time stuff.

then use “nearly equal” node
plug “delay started at” and “current game time in seconds” to A & B
then plug " delay" value into tolerance pin.

“Nearly Equal” will give you TRUE when time is up. ie it will be false for “delay” seconds. or number you put in “tolerance” pin.

I am using “nearly equal” as different flavor of “compare float”, sometimes its much better (no execution path needed) sometimes worse.

I highly suggest using Timers for this, as it’s what they’re meant for.

(1) create a custom event or function with a given name (MyLoopBody) that executes the action you want to perform in a loop

(2) Set Timer. Flag “looping”, name the function to call (MyLoopBody), and set the time to whatever you want your interval to be.

Done.

Remember, UE tries to execute all of the operations of a loop inside a SINGLE Tick/execution command. Loops are for things where you need to repeat a logic across an arbitrary number of actors/instances of something (i.e. Applying Damage to all actors overlapped by an explosion, placing a spline mesh every 200 units of distance along a spline, whatever) as if it were a single logic call. They’re not actually for LOOPING (as in repeating over time) behaviors.

Wow, looking at how many nodes go into a single basic loop makes me think Epic should have added script along with Blueprints o.O It’s just so much simpler (to me at least) and more efficient to script using code vs Blueprint noodles mess (sorry, I still can’t wrap my head around Blueprints). I know there is C++ code, but afaik C++ should be really only used for underlying gameplay framework.

i cant add delay in macros in 4.7 and 4.8 , is this a bug ?

Works fine for me in both, are you using a macro inside of a function perhaps? Because it won’t work.

i just try to do it exact like this video but there is no delay node :
https://www.youtube.com/watch?v=Mxw391exhVg

[QUOTE=vrMan;312707]
i just try to do it exact like this video but there is no delay node :https://youtube.com/watch?v=Mxw391exhVg[/QUOTE]

You sure you tried with and without “context sensitive” checked?
Try making your system on the eventGraph without using macro and then select all the nodes, right click, collapse to macro, and see if it works.
Also, you can copy/cut and paste nodes ( Ctrl-C/Ctrl-X, Ctrl-V ), so if you can insert a delay node outside of the macro, just cut, paste it into your macro.

hey Sahkan , thanks for reply
context sensitive is off . yes its working when i use collapse to macro , also copy paste isnt working on standard macros , could you tell me why i cant add delay node in standard macros ?

I honestly have no clue :confused: sorry…