Get updated bone locations after calling UpdateAnimation?

So I’m trying to attach an actor to a Pawn’s bones, but the attached actor uses the bone locations from the previous frame instead of the current one.

My game logic needs to run like this:

  1. Update the pawn’s variables that affect the animation
  2. Update the pawn’s animation based on the variables
  3. Update the attached actor’s location based on the new animation

I set the Pawn’s skeletal mesh component to PauseAnims, because I need the animation to update in the middle of the Pawn’s Tick event.

Here’s how I tried to debug it, in the Pawn’s Tick event:

UpdateAnimVars();
Print(m_skeletalMeshComponent->GetBoneLocation(TEXT("Elbow_R"))));
m_skeletalMeshComponent->GetAnimInstance()->UpdateAnimation(DeltaTime, false);
Print(m_skeletalMeshComponent->GetBoneLocation(TEXT("Elbow_R"))));
UpdateAttachedActorLocation();

I also print a debug message in the Event Graph of the Animation Blueprint, which prints out between the Elbow position messages, so I know it’s executing the Event Graph at the correct time.

The Elbow position messages both print the same vector, so it seems that UpdateAnimation doesn’t update the bone locations.

I also tried calling all of these between the Elbow position messages, but none of them changed anything:

m_skeletalMeshComponent->TickAnimation(DeltaTime, false);
m_skeletalMeshComponent->TickPose(DeltaTime, false);
m_skeletalMeshComponent->FinalizeBoneTransform();

So is there any way to force Unreal to update the bone positions in C++?

did you try to trigger your attachment using an animnotify placed on the good frame of your animation ?

The actor is essentially a capsule that’s manually attached to two separate bones, so I need it to be able to detect multiple bone’s current location on every frame.

I manually attach the actor by setting its location to be halfway between the bones and then orienting the capsule to point from one bone to the other.

I figured it out. I had to call m_skeletalMeshComponent->RefreshBoneTransforms();

1 Like