If you develop with UE4 and are writing blueprints, you already know a lot about the Flow Control macros.

Indeed, the Flow Control macros are all the macros allowing you to alter the execution flow of your blueprint (i.e. the white line connecting the nodes). The most used one is certainly the Branch node which will redirect the flow in either the true or the false path, depending on the result of a condition. Switch is similar, except it will redirect the flow depending on the value of a variable.

The ForLoop, ForLoopWithBreak, ForEachLoop, WhileLoop are also common Flow Control macros. They allow you to repeat a task several times.

All theses macros are corresponding to standard programming notions you can find in almost every language, so if you know how to program you already know how to use it. That’s why this article won’t focus on them.

But there is also several macros which are specific to UE4 and which do not have their equivalent in other languages. So, if you have learned to code using another language (which is probable), you may not be familiar with these ones, but if you know them and you know how and when to use them, they are pretty handy. This article will present them.

Sequence


The Sequence node

The Sequence macro is pretty useful to organize the code of your blueprints. Each output of the Sequence node will be called successively.

It could be easily rewritten with a single line of execution going successively through each Print String node. However, this line would take a lot of space on the screen if you want to properly organize the nodes (i have a straight line for the execution flow).

The Sequence node is here just to save you some screen space and make the whole blueprint more readable. The succession of the operations appears clearly.

A more interresting use case for this node is when you have complex and independent operations in a blueprint: this node gives more modularity. For instance, if you want to prevent the execution of a part of the blueprint (let’s say for debug purpose), you will just cut the Then link associated to this part: you don’t need to rewire anything.

DoOnce and DoN


The DoOnce node

The DoOnce node is also specific to blueprints, but there it’s not really a matter of node organization.

We know that there are parts of blueprints which may be called repeatedly, for instance the Event Tick. If we want to have some code being executed only once in the Event Tick, a classical approach would be to have a flag being set to true after the first passage, and a condition check on this flag preventing further execution, like this:


The Print String node will be called only once

This is pretty heavy to write, but fortunately, the DoOnce node allow you to do exactly the same thing but in a simpler way:


Same as before, but with the DoOnce node

This one behaves exactly like the other one. The Print String node will also be called only once. But it’s easier to read, and we don’t need to create a new variable.

Actually, we could say that the variable HasBeenDone is hidden in the DoOnce node. The Start Closed option allows us to define the initial value of this variable, and the Reset input allow us to set the variable to false, thus allowing the DoOnce to be run another time.

This being said, the DoN node is easy to understand. It’s similar to the DoOnce node, except it will allow N executions before preventing further executions. It can be used like this:


DoN node

Here, the Print String node will be called only for the first 10 occurences of the Event Tick. It’s important to note that DoN does not behave like a loop. The Print String instruction will not be run 10 times for each tick, it will be run one time per tick for 10 ticks. A use case example: you need to click 5 times on a rock to collect it (and each click will trigger the same animation).

FlipFlop

The FlipFlop node is of the same kind. It’s a convenient way to write something which would be really heavy with blueprints. Here, an example will be worth a thousand words:

This being said, the DoN node is easy to understand. It’s similar to the DoOnce node, except it will allow N executions before preventing further executions. It can be used like this:


FlipFlop node: Hello and World will be print alternatively

The first time the FlipFlop node is hit, it will run its A output. The second time it is it, it will run its B output. In this example, the first tick will print “Hello”, the second one “World”, the third “Hello”, the fourth “World” and so on.

If you want to have a specific behavior the first time an event is called, and another behavior the second time, it’s pretty useful.

For instance, if we have a chest (or a door) in a game, on the first click we open the chest, on the second one we close it, if we click again, we re-open it, etc. There, the FlipFlop node is really useful.

The output Is A indicates us in which branch we are located.

Gate


The Gate node

The Gate node allows us to control the execution flow. Technically, we can think of it as a Branch node where the False output would never do anything, and where the condition would be wether the gate is open or closed.

We can also think of it as a gate (literally), you come from Enter and you want to go to Exit. If the door is open, it’s okay, otherwise you will stop there. If you want to cross the gate, you need to Open it. If you want to prevent someone from crossing the gate, you Close it.

Here’s a small example:


Example of usage of the Gate node

Here, the Gate is initially closed (look at the Start Closed boolean parameter), so the execution flow won’t reach the Print String node (we can’t go from Enter to Exit when the Gate is closed). However, when the Event ActorOnClicked happens, the gate is opened. This means that all ticks after this event will reach the Print String node, thus “Hello world” will be printed as long as the gate is not closed. To close it, we could connect the Close input to another event.

And if we want to Open the Gate on the first click, Close it on the next one, and so on, we can use the Toggle input.
Here’s a small example:


Using Toggle

In this example, on the first click the blueprint will start printing “Hello world”, on the second one it will stop, on the third one it will start again, etc.

MultiGate


MultiGate node

The MultiGate node does not share anything with the Gate node. It’s closer to the Sequence node, but must not be confused with it.

Indeed, in the Sequence node we had several outputs being called successively. As soon as we enter the Sequence node, we know that all the output pins are going to be executed.

The behavior here is similar except that: the first time we enter the MultiGate, we will only execute the first output (Out 0), the second time we will only execute the second output (Out 1). If there are other outputs, they will be called after.


Example of usage of the MultiGate

In this example, on the first tick “Hello” will be print, then in the second tick “world”, and for the third “How are you?”.

We can ask this node to Loop: if we do so, once the last output is reached, we will start again with the first one. If we don’t want to loop, the node won’t do anything more after the execution of the last output.

We can also randomize the execution (so the selected output node will be totally random, in the example the words would appear in a random order), and we can define the index of the first output to be executed.

Reset places the node in its initial state.

Note: If we only have one output (Out 1 being connected to nothing), the behavior is the same as DoOnce. If we have two outputs and we are looping, the behavior is the same as FlipFlop.

Conclusion

If you did not know about this nodes, I hope you will be able to use it to help you when things are getting hard to write simply.

Indeed, the most important thing about the Flow Control nodes is to know that they exists.

The second most important thing is to know when to use them, but it’s something you will learn with the experience.