This page explains how blueprint graphs execute. This can be important to understand both for some potential performance implications and gotchas like Random values in Blueprints.
Node types
To fully understand how blueprints get executed, it’s first important to understand the two different types of nodes that exist:
- Normal nodes (“Impure nodes”): These are all the nodes which have a white Exec pin on them.
- Pure nodes: Any node which does not have an Exec pin.
What does "pure" mean?
It’s a reference to pure functions, suggesting the node returns the same output for the same inputs and lacks side-effects. In practice this is not the case, as many “pure” nodes have side-effects and return different values on different executions. Don’t assume “pure” means anything in Unreal, except that the node lacks the Exec pin.
Node evaluation
Node evaluation behavior is the same in blueprint graphs regardless if it’s “normal” graph, a function or a macro. They are always evaluated in sequence based on normal nodes and how their exec pins are connected.
However, normal nodes with latent execution and pure nodes have some possibly unexpected behaviors we’ll look at below.
Normal nodes
Normal nodes have the white Exec pin on them. Normal nodes are only ever executed when the exec pin connecting to them triggers. Typically this means they will only execute once, unless you have multiple exec pins connected to them.
Latent nodes
Some normal nodes are “latent”. Latent nodes usually (but not always) have two output Exec pins - an unnamed one, which triggers immediately like in non-latent nodes, and a named one which executes later. What “later” means depends on the node - for example, in Delay nodes, it’s once the specified amount of time has passed.
A possible gotcha in latent nodes is that only one “action” can exist simultaneously for a specific latent node in the graph. If you execute a latent node, it creates a “latent action”. If you re-execute the node before the latent action has finished, the node clears out the previous latent action and creates a new one.
Let’s look at this screenshot to understand it better:
Initially it might seem this graph will trigger three delays to occur. This is not the case. As mentioned above, a single latent node can only ever have one latent action running at a time. Every time the for loop triggers the delay node, the previous delay action is cleared. Only the last delay the for loop creates will ever execute.
Pure nodes
A pure node doesn’t have a white exec pin. These nodes get executed once for every connection. They also get re-executed if you create sequences of pure nodes, where a node later in the sequence has multiple connections.
Connected like below, the Random Integer node is executed two times - and you get two separate random numbers
However, in a setup like below here, you end up with four different executions of the Random Integer node!
You get two executions from the first two Add nodes, and then two additional executions for the two additional Add nodes connected to the other Add node.
This can be quite a big beginner trap especially when it comes to random values. In some cases, if you have a particularly expensive Pure node or a very large graph of pure nodes, this also has potential for impacting performance.