Prediction and lag compensation

How the client predicts its own pawn and reconciles with the host, and how the host rewinds the world to judge hits fairly.

Last updated Oct 26, 2026Edit this pageVersion 1.0.0

Two problems appear as soon as there is latency between a client and the host. Your own movement feels late if the client waits for the host to answer, and your shots miss if the host checks them against where targets are now rather than where you saw them. Mowo solves the first with client prediction and reconciliation, and the second with server rewind.

Client prediction

The client does not wait for a round trip before moving its own pawn. It applies input immediately, sends the same input to the host, and later compares its guess with the host's answer. Remote pawns are different: they are drawn from the interpolation buffer, not predicted.

For character pawns you do not wire any of this yourself. FCharacterNetDriver is a scene system that owns the whole loop FCharacterNetDriver:

  1. Capture move
  2. Step pawn locally
  3. Send moves
  4. Host queues and steps
  5. Host acks tick
  6. Compare
  7. Restore and replay
The client predicts every move, keeps a copy, and replays the unacknowledged ones only when the host's state differs from its prediction.
  1. The client records and sends a move
    Each send interval (net.PredictionSendHz, 60 by default) the driver turns the local pawn's movement intent (move axes, sprint, crouch, jump pressed and held) into a move, plus the time it covers. Every input packet repeats the newest unacknowledged moves, up to three, so one lost packet costs the host no move ReplicationInputBody.
  2. Steady moves combine
    While input does not change, the driver holds a move back and merges the next one into it instead of sending both. A move is combined only when its buttons and axes match the held one, neither carries a jump press, no root motion is active and the movement mode has not changed. The held move is sent once it covers net.MoveCombineSeconds (1/30 s, capped by net.MaxMoveDeltaTime) or the next move differs, so steady input sends about half as many moves FCharacterNetDriver::CanCombineMoves.
  3. The host queues and steps it
    On the host, the driver queues each player's moves (net.MaxQueuedMoves), snapped to the same input grid the client predicted with (see below), and steps the pawn once per move with that move's own time, through the same character movement and physics code a frame runs. Client time is bounded by the host's clock: a move larger than net.MaxMoveDeltaTime is clamped, and moves that run more than net.MoveTimeBudget ahead wait. A player that sends nothing for net.ServerForceMoveSeconds is stepped with no input, so its pawn still falls.
  4. The host acknowledges
    Only after a move ran does the host record it as processed. Every snapshot header carries that tick, so the tick a client reconciles against names a state the host actually computed. After each move the host also writes the pawn's NetMovementStateComponent: velocity, movement mode, jump count, crouch, and (owner only) the mantle, jump-hold and airborne timers NetMovementStateComponent.
  5. The client reconciles
    When an acknowledgement arrives, the client compares the host's position and movement mode with what it predicted for that tick. If the position differs by more than net.PredictionTolerance (0.25 m) or the mode differs, it restores the host's position and movement state and replays every still-unacknowledged move through the same step, including a move it is still holding back.

Move input is quantized on both ends (net.QuantizeMoves): movement axes snap to steps of 1/127 and look axes to steps of 1/100. The client predicts with exactly the values the host steps, so the rounding never shows up as a correction FCharacterNetDriver::QuantizeMove.

Because the replay runs the same Jolt character step as normal movement, a correction replayed into a wall stops at the wall. The simulation snaps but the picture does not: the pawn is drawn where it was and the difference decays over net.CorrectionSmoothTime. A correction larger than net.CorrectionSnapDistance is treated as a teleport and snaps.

CvarDefaultMeaning
net.CharacterPrediction1Client prediction with host reconciliation. 0 makes every pawn an interpolated ghost and installs no input receiver.
net.PredictionTolerance0.25Divergence in meters that triggers a restore and replay.
net.PredictionSendHz60Client move send rate.
net.CorrectionSmoothTime0.1Time constant in seconds of the visual offset that hides a correction. 0 snaps.
net.CorrectionSnapDistance2Corrections larger than this (meters) snap.
net.MaxQueuedMoves64Moves the host holds per player before dropping the oldest.
net.MaxMoveDeltaTime0.125Longest time in seconds the host steps for one move.
net.MoveTimeBudget0.25How far in seconds a client's moves may run ahead of the host's clock.
net.ServerForceMoveSeconds0.5Silence after which the host steps a pawn with no input.
net.QuantizeMoves1Snap move and look axes to the grid the host simulates with, on both ends.
net.MoveCombining1Merge consecutive moves with identical input into one.
net.MoveCombineSeconds0.0333Longest time in seconds one combined move may cover; capped by net.MaxMoveDeltaTime.

The driver exposes GetReconcileCount, GetCorrectionCount, GetLastCorrectionError and GetCorrectionOffset for a debug overlay, and GetSentMoveCount and GetCombinedMoveCount to see how much combining saves.

What predicts

Everything the character movement step simulates predicts and reconciles, because the replay calls the same code:

  • Every movement mode: walking, falling, flying, swimming, mantling, ladders, and custom modes. Register a custom mode with FCustomMovementModes::Register(id, fn, name) FCustomMovementModes and enter it with MCharacterMovementComponent::SetCustomMovementMode(id). The step function must read only the character's own components and the move's time.
  • Root-motion sources: ApplyDash, ApplyJumpForce and ApplyMoveTo on MCharacterMovementComponent MCharacterMovementComponent add a source that every movement step advances, in every movement mode including flying, swimming and ladders. Apply it on the client when the ability is predicted and on the host when it activates.
  • Jumps: maxJumpCount (air jumps), jumpHoldTime (variable height while the button is held; StopJumping releases) and coyoteTime (a ground jump just after walking off a ledge) on the character movement component.

Predicting something other than a character

The prediction bookkeeping in ReplicationManager is generic. If your pawn is not a character, you can drive it directly ReplicationManager:

CallSideWhat it does
RecordClientInput(tick, body)ClientStores the move in the pending ring and sends it.
SetInputReceiver(fn)HostReceives each client's ReplicationInputBody so you can apply it to that client's object.
SetReconcileCallback(fn)ClientCalled with the new acknowledged tick when the host has moved past inputs you predicted.
GetPendingInputs()ClientThe unacknowledged moves to replay.
TryGetAuthoritativeTransform(id, out)ClientThe host's latest decoded pose for an object.

ReplicationInputBody carries a client tick, a button mask, the move's duration in tenths of a millisecond, two move axes and two look axes. The pending ring holds up to 128 moves.

Note

The same predict, confirm or roll back model is used for ability activation in the gameplay ability system, through MFUNCTION(Server) and MFUNCTION(Client) confirm and reject RPCs on the ability state component AbilitySystemStateComponent.

Lag compensation

When a client fires, it aims at ghosts that are drawn about 100 ms in the past, plus half a round trip. If the host tested the shot against the present world, a clean hit on screen would miss. So the host keeps a short history of every networked object's pose and tests the shot against the moment the shooter saw.

  1. Client fires
  2. Send view tick
  3. RewindTo(tick)
  4. Raycast
  5. RestorePresent
The client sends the server tick it was looking at. The host rewinds, tests, and puts everything back.

How the history works

  • The host captures one pose set per server tick, which runs at 30 Hz by default and is separate from the snapshot rate.
  • It keeps 15 entries, so the window is 500 ms at 30 Hz ReplicationManager::RewindTo. SetLagCompHistoryTicks changes the count.
  • A frame hitch advances at most four ticks, so a stall cannot fill the history with copies of one pose.
  • A rewind older than the window clamps to the oldest entry rather than refusing the shot.

On a dedicated server the tick follows --tickrate. The history length in ticks stays 15, so the window in milliseconds scales with the tick rate.

Which tick to rewind to

On the client, GetClientViewServerTick() returns the server tick of the snapshot the interpolated ghosts are drawn from this frame: what the player actually aimed at ReplicationManager::GetClientViewServerTick. Send that tick with the fire request.

Rewind on the host

RewindTo(serverTick) moves every networked object back to its pose at that tick. Hit tests query physics, not transforms, so the rewind also teleports rigid bodies and character bodies by the same offset, without waking them or changing their velocity. RestorePresent() puts everything back.

LagCompensation.cpp
#include "Core/Platform.h"
#include "Networking/Replication/ReplicationManager.h"

#include <cstdint>

template<typename FHitTest>
static bool HitTestAtViewTick(Mowo::ReplicationManager& replication, uint32_t viewTick, FHitTest&& hitTest) {
	if (viewTick == 0 || !replication.RewindTo(viewTick)) {
		return hitTest();
	}

	const bool hit = hitTest();
	replication.RestorePresent();

	return hit;
}
Warning

Rewinding is not thread-safe and only makes sense on the host, between physics steps. Always pair RewindTo with RestorePresent; a second RewindTo before the restore is refused.

The Combat plugin's weapons use exactly this path: the client sends its view tick with the fire request, and the host wraps each hitscan in a rewind.

Engine sources

This page describes behavior implemented in these files of the engine repository, checked against commit 5922e6e5e.

  • Engine/Source/Runtime/Networking/Public/Networking/Replication/CharacterNetDriver.h
  • Engine/Source/Runtime/Networking/Public/Networking/Replication/CharacterPrediction.h
  • Engine/Source/Runtime/Networking/Public/Networking/Components/NetMovementStateComponent.h
  • Engine/Source/Runtime/Networking/Public/Networking/Replication/ReplicationManager.h
  • Engine/Source/Runtime/Networking/Public/Networking/Replication/ReplicationPackets.h
  • Engine/Source/Runtime/Physics/Public/Physics/CustomMovementMode.h
  • Engine/Source/Runtime/Physics/Public/Physics/RootMotionSource.h
  • Engine/Source/Runtime/Physics/Public/Physics/Components/CharacterMovementComponent.h
  • Engine/Source/Runtime/Game/Public/Game/MCharacterMovementComponent.h
  • Engine/Source/Runtime/Game/Public/Game/Components/AbilitySystemStateComponent.h

Page feedback

Was this page helpful?