What is a For Loop in Unreal Engine?
The For Loop Blueprint Node in Unreal Engine, allows you to repeat a section of your code a set number of times. This is important because if you repeat the code infinitely, it can cause issues.
The way a loop works is that you enter a “First index” and a “Last index“, and it executes whatever is connected to the “Loop Body” as many times from first to last index.
For example, if we set the first value to 0, and the second to 10, it’s going to run the code 11 times.
The “Index” is an integer number, and each time this code is executed, it increases the index value by 1.
Also, once that index value reaches the Last index value, in this example “10,” it will stop.
For a better understanding of how it works, consider connecting it to a “Print String” node, as seen in the image below. On the screen, it should count up from 0 to 10.
Create a Custom For Loop (Macro)
By double clicking the “ForLoop” node, you can modify it. This will bring up the Standard Macros tab in Unreal Engine.
Knowing this is also helpful if the For Loop node is not executing for some reason.
If you want to create a delay between loop cycles, I recommend you to watch this video.