2 min read

[19/50] Fast Path Optimizations when using Animation Blueprints

Stable Diffusion result for: "An art representing fast path optimizations."
Stable Diffusion result for: "An art representing fast path optimizations."

A lot of tutorials, especially the ones targeted at begineers, related to Animation Blueprints in Unreal embed logical operations or mathematics within the animation blueprints themselves. While this makes it easy to get started and quickly have something functional on the screen, this approach in production projects inhibits what the engine terms as Fast Path Optimizations.

From the officials docs:

Animation Fast Path provides a way to optimize variable access inside the AnimGraph update. This enables the engine to copy parameters internally rather than executing Blueprint code (which involves making calls into the Blueprint Virtual Machine). The compiler can currently optimize the following constructs: member variables negated boolean member variables and members of a nested structure.

The important part from the above statement is: executing Blueprint code (which involves making calls into the Blueprint Virtual Machine). Executing Blueprint code has performance penalty because making these calls can lead to Context Switching which implies that the CPU has to spend precious cycles to switch between the animation execution flow and Blueprint code execution.

Taking the above two images as two examples, in the first one we read a value of Rotation1 in the Animation Blueprint (ABP), do some math and assign it to the transform node. Wheras in the second one, we just read the value and assign it.

The Left hand side ABP will not compile with fast path optimizations as it has to switch between executing the Blueprint logic (math operations) and the animation flow whereas the Right hand one will.