need help with loops with delay
okay, i need to do a loop with delay (i want to spawn some enemies from a "spawner" but i don't want them to spawn together, i want a small delay between every spawn, looks better to me this way). I can't think of 3 ways of doing it first and most basic way, doing a for loop and putting a delay node in the end of it, but seems that the delay node doesn't work inside for loops and this seems to be a known problem still unsolved, so i can do it this way
the delay is ignored in this case
another way to do it is doing a "manual loop" but in this way looks like i have some kind of bug: the value of "iterator" just goes from "2" to "0" after the delay node so the branch gives false and the loop doesn't work, this makes no sense to me. i know it goes from 2 to 0 because i printed the value of iterator before and after the delay node
another way is to use "set timer by function name" it seems to don't work in functions with some kind of input, so what can i do?
asked Jun 08 '16 at 12:17 AM in Using UE4
Create your own "For Loop" macro and incorporate a delay in that. If you notice on the original For Loop, the header of the node is grey which denotes that it is a macro - double click it to open up it's internal coding. Now select everything inside and copy it all.
Back out into your blueprint you want to use it on, or better yet create your own global Macro Library. Create a new macro, call it "For Loop With Delay" then paste the code you copied into your new macro. Ensure to create input and output pins to match the original For Loop and hook it all up the exact same. To make your new macro versatile, create an added input pin of type Float and call it 'Delay'. In the proper section of the macro, add a 'Delay' node and either enter the desired delay or if you created the input pin, plug that into the delay and VOILA! You're own 'Custom' For Loop with built in Delay!
NOTE: The method shown in the first image will still have a delay of your designated time before the 'Completed' execution pin runs. This may be an undesirable side effect. This can be easily fixed with a simple branch to check if the current integer is greater than the last index and if it is, don't execute the delay. See the final image for that alternative method.
Here's some images to help you understand! If this solved your problem please do me a favor by accepting the answer as correct! Remember that commenting after you accept the answer deselects it as accepted. You'll know it's good when it stays green! Thanks and Good Luck!
You can't place delay in loops, you have to make your own :
answered Jun 08 '16 at 08:37 AM
I would definitely recommend to use the "SetTimerByFunction" blueprint and repeat this as many times as possible. Each time it is called it will handle finding a valid spawn point etc.. If you have to pass data in, simply save it into a variable. I believe this method is much smoother and cleaner than using a delayed for loop.
Follow this question
Once you sign in you will be able to subscribe for any updates here