top of page
Search
  • Writer's pictureBob Cober

UE4 Root Motion


I have seen constant confusion surrounding what root motion is and whether it works over the network or with NavMesh. After spending some time implementing this, I hope this post might bring some information to light.

Overview

Root motion in this context refers to the notion of applying the transformation and rotation information from the root bone of an animation directly to the Character Actor in Unreal.

In this sense, root motion replaces the need to calculate the movement in code and instead enables the animation to determine it.

For example, consider a typical zombie walk. Typically, one might play a walking animation and at the same time apply movement to the pawn. An animation without root motion is often referred to as an in-place animation. The animation typically relies on constant linear movement, and as long as the movement applied to the pawn matches that speed, then the feet will not slip and the zombie will appear to walk forward. Of course, sometimes this can be difficult to match up perfectly right, and any increase/decrease in pawn movement speed needs to be accompanied by a matching change in the animation playback speed. Otherwise, this can result in foot sliding e.g. the moonwalk.

To use root motion to drive the movement instead, one first needs to create or obtain an animation with movement and/or rotation applied directly to the root bone, typically done in an animation authoring tool such as max or maya. In addition, many of the assets on the Marketplace include both Root Motion and In-Place animations. When a Root Motion animation is played in unreal, that motion on the root bone is applied to the Character instead of to the root bone. Unreal has already implemented full-support for Root Motion in the Character actor. Thanks Unreal!

Why

So what are the benefits of using root motion? It keeps the collision capsule anchored to the mesh where it should be, it enables you to utilize acceleration and deceleration in your animation, it eliminates foot sliding and other artifacts, and it simplifies the programming work load.

Can I use root motion on my Player-controlled pawn?

Yes - but instead of the joystick axis controlling how much force to apply or directly modifying transformation to apply, instead it controls which animation to play and how fast to play it. Controlling you character == controlling the animation that is playing playing. Want to walk faster? Play the animation to walk faster. Want to turn 90 degrees? Play an animation that turns 90 degrees.

Does it work with vertical root motion? Yes, but remember, your character movement component needs to be flying.

Does root motion work with blending?

Yes, the animations are blended, and the resulting blended transform from the animations on the root are applied.

Can I use root motion for my AI enemies?

Yes - as with a player pawn, the Behavior Tree needs to control what animation is being played.

Does it work with AI MoveTo?

No, MoveTo moves the actual pawn. But there is an alternative: just use the underlying path nodes to orient the agent's direction. Remember, as long as the pawn is facing the correct direction, root motion will drive it toward that location. So instead of using AI MoveTo, you can use FindPathToActor to generate a list of path points, and use them to orient the direction the agent is facing.

Network Considerations

Does root motion over the network?

Yes. But there are a few things to remember. Since the AnimBP is NOT replicated, and the AnimBP is controlling the motion, the state of each AnimBP needs to be kept in sync in some other manner. In order to keep animations in sync, make sure to replicate the correct variables on the character. A common pattern in Epic tutorials is using the UpdateAnimation even on the AnimBP to read in variables from the owning pawn and update the AnimBP state variables. If you follow this pattern, then all you need to do to keep your animations in sync across the network is to make sure the character variables are replicated.

Is the built-in network correction/client side prediction code utilized?

Yes. Position reconciliation for root-motion driven characters is present in the CharacterMovementComponent. Client side prediction is not really needed, since the location of the actor between network updates is determined by the root-motion from the animation playing.

Video

I created a short tutorial video to illustrate using Root Motion over the network:


8,374 views0 comments

Recent Posts

See All

New Content On Epic

I have been posting new content directly to Epic:  https://dev.epicgames.com/community/profile/vElq/OptimisticMonkey#learning

bottom of page