Editor crash (array out of bounds) evaluating an Anim Blueprint with input pose on a MetaHuman head mesh

Summary

UAnimPoseExtensions::EvaluateAnimationBlueprintWithInputPose (Python: unreal.AnimPoseExtensions.evaluate_animation_blueprint_with_input_pose) asserts and closes the editor when the target skeletal mesh’s required-bones set is smaller than the mesh’s bone count. A MetaHuman head mesh with ABP_Face_PostProcess reproduces it every time. A MetaHuman body mesh with ABP_Body_PostProcess works, because every bone is required there. The assertion cannot be caught from Blueprint or Python, so the whole editor goes down with any unsaved work.

What Type of Bug are you experiencing?

Animation

Steps to Reproduce

  1. Create a MetaHuman with the MetaHuman Creator plugin and assemble it, so the project has its head skeletal mesh (Face_Archetype_Skeleton) and /MetaHumanCharacter/Face/ABP_Face_PostProcess.
  2. Create any AnimSequence on the face skeleton (a few frames; its content does not matter).
  3. Run this in the editor’s Python console (fill in the two asset paths):

import unreal
mesh = unreal.load_asset(‘/Game//’)
anim = unreal.load_asset(‘/Game//’)
abp = unreal.load_object(None, ‘/MetaHumanCharacter/Face/ABP_Face_PostProcess.ABP_Face_PostProcess’)
X = unreal.AnimPoseExtensions
opt = unreal.AnimPoseEvaluationOptions()
opt.set_editor_property(‘optional_skeletal_mesh’, mesh)
pose = X.get_anim_pose_at_frame(anim, 0, opt)
out = X.evaluate_animation_blueprint_with_input_pose(pose, mesh, abp) # editor crashes here

Expected Result

The output pose is filled with the blueprint’s result, or the function logs an error and returns. It should not assert.

Observed Result

The editor crashes: “Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:Runtime/Core/Public/Containers/Array.h] [Line: 1339] Array index out of bounds: 737 into an array of size 737”, raised from FBoneContainer::GetParentBoneIndex called by FAnimPose::Init.

Affects Versions

5.8

Platform(s)

Mac

For crash reports, include your callstack

Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:Runtime/Core/Public/Containers/Array.h] [Line: 1339]
Array index out of bounds: 737 into an array of size 737

libUnrealEditor-Core.dylib!FDebug::CheckVerifyFailedImpl2(char const*, char const*, int, char16_t const*, …)
libUnrealEditor-Engine.dylib!FBoneContainer::GetParentBoneIndex(FCompactPoseBoneIndex const&) const
libUnrealEditor-AnimationBlueprintLibrary.dylib!FAnimPose::Init(FBoneContainer const&)
libUnrealEditor-AnimationBlueprintLibrary.dylib!UAnimPoseExtensions::EvaluateAnimationBlueprintWithInputPose(FAnimPose const&, USkeletalMesh*, UAnimBlueprint*, FAnimPose&)
libUnrealEditor-AnimationBlueprintLibrary.dylib!UAnimPoseExtensions::execEvaluateAnimationBlueprintWithInputPose(UObject*, FFrame&, void*)
libUnrealEditor-CoreUObject.dylib!UFunction::Invoke(UObject*, FFrame&, void*)
libUnrealEditor-CoreUObject.dylib!UObject::ProcessEvent(UFunction*, void*)
libUnrealEditor-PythonScriptPlugin.dylib!PyUtil::InvokeFunctionCall(UObject*, UFunction const*, void*, char16_t const*)
libUnrealEditor-PythonScriptPlugin.dylib!FPythonScriptPlugin::ExecPythonCommandEx(FPythonCommandEx&)
libUnrealEditor-PythonScriptPlugin.dylib!FPythonScriptRemoteExecutionCommandConnection::Tick(float)
UnrealEditor!FEngineLoop::Tick()

Additional Notes

Likely cause, from the 5.8 source (Engine/Source/Editor/AnimationBlueprintLibrary/Private/AnimPose.cpp, FAnimPose::Init):

for (const FBoneIndexType BoneIndex : InBoneContainer.GetBoneIndicesArray())
{
const FCompactPoseBoneIndex CompactIndex(BoneIndex);
const FCompactPoseBoneIndex CompactParentIndex = InBoneContainer.GetParentBoneIndex(CompactIndex);
…
RefLocalSpacePoses.Add(InBoneContainer.GetRefPoseTransform(FCompactPoseBoneIndex(BoneIndex)));

GetBoneIndicesArray() holds mesh pose bone indices, one per compact pose bone, but the loop uses each value as a compact pose index. The two only coincide when every bone of the mesh is required. In EvaluateAnimationBlueprintWithInputPose the container is AnimInstance->GetRequiredBones() of a temporary component; for the MetaHuman head it holds 737 bones while the mesh has more, so a mesh index of 737 or above indexes the 737-entry compact parent array. Where it does not assert, the same loop would pair the wrong parents and reference transforms whenever the required set has gaps.

Suggested fix: iterate compact indices (0 .. GetCompactPoseNumBones()-1) and pass that FCompactPoseBoneIndex to GetParentBoneIndex, GetSkeletonIndex and GetRefPoseTransform.

Seen on macOS (Apple Silicon), launcher build of 5.8; the code is platform independent. Workaround: none from script; we stopped calling the function on face meshes.