Transform multiple bones same animation blueprint

Hi Guys,

I’m trying to transform multiple bones in the same custom animation blueprint. I’m using the Transform (Modify) Bone code present in the source of the engine

    void FMyClassAnimNode::EvaluateBoneTransforms(USkeletalMeshComponent* SkelComp, FCSPose<FCompactPose>& MeshBases, TArray<FBoneTransform>& OutBoneTransforms)
    {
        check(OutBoneTransforms.Num() == 0);
        
        const FBoneContainer& BoneContainer = MeshBases.GetPose().GetBoneContainer();
        
        FCompactPoseBoneIndex CompactPoseBoneToModify = BoneToModify.GetCompactPoseIndex(BoneContainer);
        FTransform NewBoneTM = MeshBases.GetComponentSpaceTransform(CompactPoseBoneToModify);
        
        FAnimationRuntime::ConvertCSTransformToBoneSpace(SkelComp, MeshBases, NewBoneTM, CompactPoseBoneToModify, RotationSpace);
        
        FRotator Rotation = FRotator();
        Rotation.Pitch = 1.0f*counter;
        
        const FQuat BoneQuat(Rotation);
        NewBoneTM.SetRotation(BoneQuat * NewBoneTM.GetRotation());
        
        FAnimationRuntime::ConvertBoneSpaceTransformToCS(SkelComp, MeshBases, NewBoneTM, CompactPoseBoneToModify, RotationSpace);

         counter++;
OutBoneTransforms.Add(FBoneTransform(BoneToModify.GetCompactPoseIndex(BoneContainer), NewBoneTM));
    }

To do the additional transformation I just use BoneToModify2 that contains the reference to the another bone and replicate this code after the OutBoneTransforms.Add. But the moment I update the animation blueprint for this code it just breaks unreal… Does anyone know why? And how to fix this?

Thanks!

This is possible by changing a little how you apply your transforms inside EvaluateSkeletalControl_AnyThread

In essence you change the line at the end from

OutBoneTransforms.Add(FBoneTransform(compactbone, NewBoneTM));

to:

TempTransforms.Add(FBoneTransform(compactbone, NewBoneTM));
Output.Pose.LocalBlendCSBoneTransforms(TempTransforms, BlendWeight);
TempTransforms.Reset();

Which applies each transform before processing the next transform if it’s placed inside a loop going over each of your bones.

1 Like

This has really helped, thank you! Any downsides to this approach that you are aware of?