Performance Optimization - Vaei/TurnInPlace GitHub Wiki
[!CAUTION] Advanced C++ Users Only ActorTurnInPlace Version >= 1.4.2
[!WARNING] This guide is only useful for release-tier products with large character counts squeezing out all possible optimization Don't waste your time here otherwise
Rough frame costs from an in-editor test from dedicated server with ~100 characters (thus not particularly accurate):
UTurnInPlace::FaceRotation
32μs
UTurnInPlace::UpdateAnimGraphData
20.7μs
UTurnInPlace::OverrideTurnInPlace
7.5μs
ITurnInPlaceAnimInterface::GetTurnInPlaceAnimSet
7.5μs
[!WARNING] The server is using
DedicatedServerAnimUpdateMode == ETurnAnimUpdateMode::Pseudo
for these tests
These values are not significant, but when added up over 100 characters over an entire frame, they can make a meaningful difference if we reduce them.
Typically the current FTurnInPlaceAnimSet
changes when we change stance or when the anim layer changes, your game may have animation states or other variables that affect it. You may find that updating on tick within the anim graph is sufficient simply to avoid an interface call. Regardless, if you find an appropriate way to cache the current anim set then you could subclass UTurnInPlace
component, override OnAnimInstanceChanged()
and cast AnimInstance
to your own, and grab the cached value in UTurnInPlace::GetTurnInPlaceAnimSet()
however, it is not virtual and will not be made virtual, so you will need to fork this plugin to make it virtual.
[!TIP] You can respond to anim layer changing by overriding
UAnimInstance::LinkAnimClassLayers()
andUAnimInstance::UnlinkAnimClassLayers()
OverrideTurnInPlace()
is a BlueprintNativeEvent
, modifying the forked plugin to be a virtual function and handling this entirely in C++ may gain something worthwhile (may not also).
These changes brought the cost of UTurnInPlace::FaceRotation
from 32μs to 13μs