Ask Unreal Anything: Animation | July 13, 2022 at 11AM EDT

We’ve actually gotten this question before, and I’m lazy so I’m going to copy and paste our response from that here as well.

Question: "Root motion import orientation changes extraction behavior
Prior to 5.0 we were able to import animations from Maya that had an arbitrary forward orientation. Then when importing to Unreal and enabling root motion on the animation it would move as it did in Maya, with both mesh and root motion oriented in that arbitrary direction, animation however was correct and looked as it did in Maya.

With 5.0 we see a different behavior, and animations that aren’t facing positive X will not get their root motion extracted properly. We’ll see the actor moving in one direction and the mesh facing in a different direction. So what we’ll see in Maya is inconsistent with what we see in the Editor. It’s not just an axis change, it seems like root motion extraction assumes an orientation somewhere and creates a mismatch between motion data and the mesh orientation.

This can be seen in the animation editor, when selecting Character > Animation > RootMotion > Loop (or Loop and Reset). The behavior is the same when animating a character in game.

Is this an intended change? Is it a known bug?"

Answer: "We are aware of this. It is indeed an ‘issue’ we introduced with a change we made in UE5 to be able to import and use root motion animation offset from the origin, which is something that improves the workflow for multi actor interactions and it wasn’t possible in UE4.

We have discussed this internally and we think this is a content error and the engine should not be dealing with that when extracting root motion. Our plan is to provide a way to fix the orientation of your animation in the engine but there is not ETA for that yet. In the meantime you have two options:

  1. Go back to the DCC and fix the orientation of the mesh in the animation. The mesh in the animation should have the same orientation than the ref pose (e.g if the mesh is facing X axis in the ref pose the mesh in the animation should be also facing x axis).

  2. If you can modify the engine locally and you don’t need to be able to import root motion animation offset from the origin you can replace UAnimSequence::ExtractRootMotionFromRange with code below which is what we had in UE4."

FTransform UAnimSequence::ExtractRootMotionFromRange(float StartTrackPosition, float EndTrackPosition) const
{
const FVector DefaultScale(1.f);

FTransform InitialTransform = ExtractRootTrackTransform(0.f, NULL);
FTransform StartTransform = ExtractRootTrackTransform(StartTrackPosition, NULL);
FTransform EndTransform = ExtractRootTrackTransform(EndTrackPosition, NULL);

// Use old calculation if needed.
if (bUseNormalizedRootMotionScale)
{
	//Clear scale as it will muck up GetRelativeTransform
	StartTransform.SetScale3D(FVector(1.f));
	EndTransform.SetScale3D(FVector(1.f));
}
else
{
	if (IsValidAdditive())
	{
		StartTransform.SetScale3D(StartTransform.GetScale3D() + DefaultScale);
		EndTransform.SetScale3D(EndTransform.GetScale3D() + DefaultScale);
	}
}

// Transform to Component Space Rotation (inverse root transform from first frame)
const FTransform RootToComponentRot = FTransform(InitialTransform.GetRotation().Inverse());
StartTransform = RootToComponentRot * StartTransform;
EndTransform = RootToComponentRot * EndTransform;

return EndTransform.GetRelativeTransform(StartTransform);

}

Follow Up Question: “Thanks. Could you explain a bit more about how it’s useful for multi actor interactions to have root motion offset from the origin? What exactly is the difference in the motion extraction approaches?”

Answer: Hopefully I get some time before 5.1 release to fix it.
Unfortunately we don’t have an example of how to use it. So it may be a bit difficult to understand for non technical people. It basically ask you for a rotation that you want to apply to bring the mesh to face the same axis the ref pose is facing. Unfortunately I don’t think there is a way to do that automatically (or at least I can’t find one) "For multi actor interactions you need to know the location of each actor relative to the other at any point in the animation to ensure they are perfectly aligned during the interaction. Same thing for IK, you usually need to know things like where the hand of char A should be relative to the head of char B to fix contact points when playing the interaction on uneven terrains for example.

In UE4 when extracting root motion we were counter rotating the root transform with the rotation in the first frame (as you can see in the function above). That was done to deal with the problem that you described, but when doing that now you are not able to have root motion animations offset from the origin (root motion will move the actor in the wrong direction, similar to what you are seeing now). When working on interactions the animator will animate the interaction in the DCC with each actor perfectly aligned relative to the other but after importing the animation they had to reset the position/rotation of each actor back to the origin, so root motion can be applied fine. This prevented us from simply extracting the bone transform of each animation at the same time to know where one actor should be relative to the other during the interaction so now the animator will have to create an extra bone in the skeleton that represents that information, this could cause a few problems specially if this bone wasn’t considered at the beginning of the project. Also, depending on the animator’s experience, sometimes the process of adding this bone requires a little bit of back and forth to understand how that bone should be created (should it be a child of the root, should it move with the root etc).

On the other hand, being able to import the animation offset from the origin allows us to simply extract all that information at runtime without extra bones in the skeleton and the animator now doesn’t need to worry about resetting the animation back to the origin before exporting or adding and animating extra bones.

But regardless of all that, we just think that the engine should not be trying to make sense of the content when extracting root motion, the idea of counter rotating the root motion with the rotation in the first frame of the animation was made to try to deal with something that is a content error, prove of this is that it commonly happens when users are importing animations from different marketplaces without really understanding how the animation was created and expecting it to just work. Unfortunately there is no way (as far as we know) of fixing this problem entirely, as you can see one approach fixes something but breaks in some other case. That’s why after discussing this internally we decided that the best option is to not add extra code to the root motion extraction to try to deal with all those cases and instead provide an easy way for the user to fix their animation in the engine. We are hoping to get it done soon, we are thinking that an animation modifier will do it."

We also now have (in UE5 main) a new AnimModifier (ReOrientRootBoneModifier) to fix the animation. However, it has a bug right now if the animation is using a different skeleton. We will likely have a fix for this by 5.1 though. Unfortunately we don’t have an example of how to use it so it may be a bit difficult to understand for non technical people. It basically ask you for a rotation that you want to apply to bring the mesh to face the same axis the ref pose is facing. I don’t think there is a way to do that automatically yet.

1 Like