For Loop
Inputs | |
---|---|
First Index | Starting value for Index will be assigned. |
Last Index | Final value Index reaches for loop completion. |
Outputs | |
---|---|
Loop Body | Execution Pulse for each iteration of the loop. |
Index | Current iteration counter the loop is on. |
Completed | Execution Pulse after the loop has reached the Last Index and finished the Loop Body pulse. |
There are multiple ways to create a for loop in C++. This example matches very closely to the blueprint node.
Overview
For Loop will perform a series of runs for the designated amount of times.
The starting and final values can be modified, and the current loop counter can be tracked with Index. At the start of each iteration, the Loop Body pin pulses to run the logic of the loop. On the last iteration, after Loop Body finishes, Completed will pulse.
This works like your standard For Loop in C++, except a bit more rigid. Where the incrementing occurs and the finished condition cannot be changed and cannot break.
If breaking is required, there is a For Loop With Break node with the extra functionality.
Warnings
The entire loop will run in a single linear flow when executing. In most cases, the loop has to finish before any other logic runs.
If the iteration count of the loop is very high or the logic inside it is heavy, it could cause performance problems.
Examples
Object Construction
Using the For Loop in the Construction Script, we can procedurally create an adjustable amount of cylinders with offsets between them. Here the Barrel Count is set to 5, and the Offset is 100.
OnConstruction is not a 1:1 native version of the Construction Script. It should work for most situations, but there may be cases in which extra functions are needed.