x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 For + delay

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 alt text

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? alt text

Product Version: UE 4.11
Tags:
opt1.png (339.3 kB)
opt2.png (116.0 kB)
opt3.png (340.9 kB)
more ▼

asked Jun 08 '16 at 12:17 AM in Using UE4

avatar image

veccher
1.1k 31 16 65

avatar image ViceVersa Jun 08 '16 at 01:34 AM

i think a much simpler way to fix your issue, make a function with all the spawning stuff in it make a boolean called "canSpawn" or something like that from event tick, make a branch that checks this boolean. if its true, call the function, at the end of the funciton set the boolean to false. and set your timer variable to some value From the false part of the branch, subtract delta time from the float variable. then check if it equals zero, if it does, set canSpawn to true

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

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!

alt text

alt text

alt text

more ▼

answered Jun 08 '16 at 08:14 AM

avatar image

jtsmith
1.4k 70 29 91

avatar image veccher Jun 10 '16 at 04:41 PM

ty but it seems that i can't place a delay node in a macro, so i can't accept your answer, at least not yet no delay

no delay.png (326.7 kB)
avatar image veccher Jun 10 '16 at 04:54 PM

PS.: ok it looks like its possible to put the "delay" node in a "local macro" but it's not working, the delay is just being ignored.

avatar image ViceVersa Jun 10 '16 at 05:04 PM

Just put the delay node right bwfore the macro gets called

avatar image jtsmith Jun 10 '16 at 06:37 PM

Putting a delay before a loop does not delay the execution of each iteration inside the loop body, it only delays the initial execution of the loop. Creating a custom macro and setting it up exactly as I show in the images is how to create a for loop with custom delay so that the loop body delays on each iteration.

avatar image jtsmith Jun 10 '16 at 06:34 PM

Correct, you can put a delay into a macro but you can't, nor do you want to, put one in the original Standard Macro. Send some SS of what you did because if the delay isn't working inside your custom macro you did something wrong. It works fine for me and I use my custome for loops with delay frequently with no issues.

avatar image veccher Jun 14 '16 at 12:55 AM

ok, just opened the project today and it was working, i used something similar to your first SS because i need the delay in the last node in this case.

(comments are locked)
10|2000 characters needed characters left

You can't place delay in loops, you have to make your own :

Loop iterations will take place between frames, so large loops may incur a performance hit.

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/#forloop

more ▼

answered Jun 08 '16 at 08:37 AM

avatar image

mdonge
825 31 12 37

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Jun 09 '16 at 05:20 AM

avatar image

PantherNZ
66 5 7 15

(comments are locked)
10|2000 characters needed characters left

Very close to what jtsmith said to do, a macro in the BP. But replicating the ForEachLoop's Macro with a delay.

https://imgur.com/LQufWtA

https://imgur.com/YEM3tpr

more ▼

answered Mar 28 '19 at 07:27 PM

avatar image

Death_Dealer_33
8 1 2

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question