How to Spawn AI Actor using a Loop with a Delay?

OK, so i have this idea of a controlled spawning of AI Bots to the level. They have their respective programming and everything is working fine. I want the 2 different type of bots to spawn with a random delay between 0 and 3 seconds. I tried the calling 20 spawn AI Actors, but i know there is the loop function that will make this relatively shorter. So i’m trying but it’s either an Infinite Loop or It hits the max number almost instantaneously. I’m using a Sequence because i’m trying to use 10 on each type of bots (i currently have only two types at the moment) but i don’t think that’s the problem. Any help will be Greatly Appreciated!!

PS: The ForLoop is connected to an Event Begin Play

You shouldn’t use delays within loops. UE4 freezes the game until a loop is completed. I believe there was a tutorial on modifying the loops to allow for these kind of delays. Try searching Unreal Engine channel for it.

I don’t think a loop is what you want.

You always have to remember that a loop will do whatever it does the second it’s called.
It usually will run through in one tick meaning that you spawn everything at once.

Also note that the for loop runs with a sequence meaning that it will automatically run the next line no matter if the body finished and by pulling your lines into the for loop again you just start a new one meaning you create an infinite loop which calls more of itself every time it runs through.

You can modify the for loop a little taking input before running it’s body again. You have to set a new “exec” input within the for macro and pull that into one of the sequence destinations (I hope you understand how that macro works otherwise just tell me and I’ll show you a picture of how to set up the change).

Or your second option would be to just ignore the for loop and use the general “Event Tick” as your loop. Checking how many you spawned and using random delays. The Tick will not cause multiple delays but just “die out” meaning that you can use “Delay” to stop a line from executing for a while.

…I hope I explained it in an understandable way otherwise just ask me whatever you did not understand :slight_smile: