Hello Epic Support team !
We recently noticed some hitches when spawning pawns around our project. We tracked down the problem to the linking phase of our AnimLayers. After further investigation and instrumenting a lot of what was going on around here, we found out that when linking an AnimInstance whose main AnimGraph contains a LinkedLayerNode linked to its own anim layer graph, Unreal initializes the anim layer graph twice :
- First, through the linked AnimInstance’s InitializeAnimation() > FAnimInstanceProxy::InitializeRootNode() which leads to initializing the LinkedLayer node following the graph from the root node. This will make the linked layer node initialize its subgraph : the linked instance self layer.
- And a second time at the end of the linked AnimInstance’s InitializeAnimation() when calling UAnimInstance::InitalizeGroupedLayers() > UAnimInstance::PerformLinkedLayerOverlayOperation() > InitializeAndCacheBonesForLinkedRoot(). Here, PerformLinkedLayerOverlayOperation() considers that the node should be linked to “self”, and therefore, initializes the graph (which has already been linked and initialized by the previous step)
This process can be repeated even further if the anim layer graph evaluates another anim graph which follows the same structure (through an LinkedAnimGraph node for example). This leads the deepest layer graph to be initialized thrice, causing several hitches when adding our pawns to the game.
Our animation / gameplay teams like to make the main graph call its layer anim graph as it allows to preview the result of the graph in the AnimBlueprintEditor easily (without requiring to layer the graph onto another AnimInstance) while also making it usable both as a linked anim layer and as a linked anim graph.
I’ve tried patching the engine to prevent these multiple initializations by making the LinkedAnimGraph & LinkedAnimLayer nodes track whether they have already initialized or uninitialized their subgraph and by checking this state when UAnimInstance::PerformLinkedLayerOverlayOperation() attempts to initialize it in order to avoid initializing an already initialized graph.
Following this investigation, I have a few questions :
- Do you think this is an actual bug or has the issue more to do with the way we structure our ABPs ?
- Are there some aspects that I may have overlooked that require these repeated initialization and cache-bones calls ?
- Does the solution I’m implementing seem like a reasonable way to address to this problem ?
Thank you for your consideration,
Best regards,
Thomas
[Attachment Removed]