Issues to note when using BlueprintPure in UE5

Preface

The function specifier BlueprintPure is used with UFUNCTION to complete the function tagging and provide additional descriptions of the function behavior. The main intention is to provide functions without white execution pins for blueprint use. You can check the official documentation (Click here, the English comments are clearer, and the Chinese comments are cut corners)

Operation purpose: In the blueprint, remove the white execution pins of the marked function, so that the called node is not "directly introduced into the execution logic line", so that the blueprint execution logic looks neater.

Function with execution pin removed

In Blueprint

To hide the execution pin, check "Pure Function" in the function's details panel in the Blueprint

In Blueprint

In C++

You can hide the execution pin by adding "BlueprintPure" to the function description or by making the function a normal function

1UFUNCTION(BlueprintCallable, BlueprintPure)
2int32 CallFunc1();
3UFUNCTION(BlueprintCallable)
4int32 CallFunc2() const;

Summary of the problem

  • Since pure functions lack execution pins, the rule for calling pure functions is: connect the output execution line to the node in the execution logic, so pure functions need to have a return value, that is, they need to have an output pin
  • In C++, if a function marked with BlueprintPure has no return value, compilation will fail (BlueprintPure specifier is not allowed for functions with no return value and no output parameters.)
  • Functions in blueprints can have no return values. Check pure functions, but calling functions in the graph will not be able to add execution logic lines
  • For pure function blueprints, the number of executions of the function itself needs to be noted
  • If there are multiple input pins in an execution node, and each pin is connected to the same pure function, the pure function is only called once
    Figure a Execute once
  • If multiple nodes on an execution logic line input the same pure function multiple times, the function is called multiple times
    Figure b Execute multiple times

Regarding the number of calls, pure functions are somewhat different from ordinary functions

Figure c Ordinary function is executed once
Ordinary function output pins are connected multiple times but are only executed once

The rules are simple:

  • On the white execution line, as long as there is a connected execution node, the node call logic will be executed once. As for the node input, multiple functions are associated, and each function is only executed once (Figure a). Even if the function is connected multiple times, it is only executed once.
  • If the function is called by different execution line nodes, the node will also be called multiple times (Figure b).
  • For non-pure functions, there is an output value after execution. No matter how many times the output value is connected, it will not cause the function to execute (because the execution has passed and will not be reversed Figure c)

Conclusion

When using pure functions, remember the number of calls. For example, if you write a factory method to produce objects, if you mark the factory method as a pure function, be sure to pay attention to the fact that multiple calls in the execution logic line will generate objects multiple times.

Translations:

Comment