Course contentsShow
← Unreal Engine Game Development
Lesson 730 of 88010. Networking and ReplicationFree lesson

Applying Root Motion in Networked Games

Configure character animations to drive movement while ensuring the server correctly tracks and replicates the resulting positional changes.

In this lesson, you will learn how to synchronize animations that move the character’s capsule to ensure the server and client remain in perfect alignment.

The Challenge of Root Motion

When you use Root Motion, the animation itself dictates the character's movement, extracting translation data directly from the mesh’s root bone. In a networked environment, this poses a synchronization nightmare: if the client plays a 2-second leap animation, the server must calculate the exact same displacement. If the client’s frame rate dips or packet loss occurs, the client and server positions will drift, triggering the CharacterMovementComponent to force a reconciliation, causing the dreaded "rubber-banding."

Configuring Root Motion for Networking

To handle this, you must offload the root motion calculations to the CharacterMovementComponent. Instead of just playing an animation, you tell the component to process the root motion data through the standard movement pipeline.

  1. Enable Root Motion: In your UAnimMontage, set "Root Motion Mode" to Root Motion from Everything.
  2. Server-Authoritative Processing: You must ensure the CharacterMovementComponent is aware of the root motion. When using PlayMontageAndWait or PlayAnimMontage, the component hooks into the movement flow.
  3. The Replication Hook: Set bAllowPhysicsRotationDuringAnimRootMotion or rely on the RootMotionSource system. By using RootMotionSource, you explicitly define movement patterns that the server can track and replicate as part of the SavedMove data during client-side prediction.
// Within your Character class, ensure movement reflects the animation
void AMyCharacter::PerformRootMotionAttack()
{
    // Ensure the Server initiates the montage so clients sync correctly
    if (HasAuthority())
    {
        MulticastPlayAttackMontage();
    }
    else
    {
        ServerPlayAttackMontage();
    }
}

The key is that the server must execute the same animation logic. Because the CharacterMovementComponent tracks RootMotionSource during its simulation ticks, the server validates the movement frame-by-frame. If the client tries to "cheat" or desync by playing an animation that moves them through a wall, the server’s authoritative simulation will override the client’s position during the reconciliation process.

Key Takeaway: Root motion in networked games must be processed through the CharacterMovementComponent’s authoritative simulation pipeline to ensure the server validates and replicates movement displacement rather than just animation playback.