Menu

Netcode for Unity Multiplayer: Client-Side Prediction and Lag Compensation Explained
📰

Netcode for Unity Multiplayer: Client-Side Prediction and Lag Compensation Explained

DEV Community: csharp·Matthew Anderson·about 5 hours ago
#zN94do5Q
#devtocsharp#devto#dev#server#client
Long article (1336 words) — no AI summary yet.
Reading 0:00
15s threshold

A player presses the move key. On a single-player build, the character moves on the next frame. In a server-authoritative multiplayer build, that input has to reach the server, get simulated, and come back before anything is confirmed. On a 60ms round trip that is roughly four frames of delay at 60fps. On a mobile connection it can be fifteen.

However, players read that delay as the game feeling heavy or unresponsive. They rarely report it as latency, so it usually arrives as “the controls feel wrong”.

Three techniques handle it: client-side prediction, server reconciliation and entity interpolation. A fourth, lag compensation, deals with hit detection. They are not alternatives. A shipped multiplayer game normally runs all four at once, and each one solves a different half of the problem.

This writeup covers how they fit together in Unity, with the parts that break in practice. The code below uses Netcode for GameObjects, though the same structure applies to Mirror, Fish-Net or a custom transport.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.