How to add a delay inside FOR or FOREACH loop inside a function? It seems impossible (design limitation, can’t put Delay nodes inside function ) but how to achieve this in some workaround-way?
For example: Let’s say i want to, for each Bob to say “Hello”, wait 2 seconds and iterate this loop again, with another Bob saying “Hello”. Effect: Every Bob on my scene will say “Hello” with 2 seconds interval.
All this inside a ‘MakeAllBobsSayHello’ function How to achieve this?
SO are you using a Loop or you just want it to loop?
I’ve redesigned my question to be more specific, with an example So now the question is, how to make every Bob say ‘hello’ with 2 seconds delay inside a function?
Use a custom event, not a function.
OK, i did it: First, use custom event instead a function, as @ suggested. But that doesn’t solve the problem, because foreach loop will not respect delay node and execute all Bobs at once. [HERE][1], in @ answer, there is an instruction how to modify for loop to respect Delay node. After modifying it this way, just setup it like this:
Now, all Bobs on scene will say Hello with interval specified in Delay node
Thanks for suggestion, that doesn’t solve the problem because of FOREACH loop not respecting Delay node, but i’ve posted a workaround. +1 for You ^^
That is simple. Make a boolean which will determine if the function is supposed to be looping and on the outer node of delay, bring it back to For Each Loop.
This will still execute all array items (all foreach iterations) at once, because foreach loop doesn’t respect Delay nodes. I’ve already found a solution though (with use of modified ForEach), it’s in the answer
This could be another approach:
(UE4.10) → Using “[Set timer by function name][1]” (link to the Unreal Docs).
Using this node, with the loop checked, and setting the for 2 seconds (from your question description) will produce similar effect that will solve the task (trigger a “hello” every two seconds).
https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseTimers/Blueprints/index.html