In this lesson, you will learn how to bridge the gap between your server’s logic and the client’s visuals by broadcasting essential object properties to ensure every player sees the same game state.
When building an authoritative server, the server is the "source of truth." However, the clients are the ones rendering the game. To keep the experience seamless, you must use State Synchronization. This is the process of periodically sending the server’s calculated data—like position, rotation, or health—to all connected clients so they can update their local copies.
The Replication Pattern
Data replication is most effective when you use a "snapshot" approach. Instead of sending every single frame's delta, you define a Data Transfer Object (DTO) that contains the minimal set of variables required to represent the object's current state.
For example, a PlayerState struct might look like this:
public struct PlayerState {
public int networkId;
public Vector3 position;
public Quaternion rotation;
public float health;
}
On the server, you broadcast this state at a fixed interval (often 20Hz or 30Hz). When a client receives this packet, it applies the values to the corresponding local game object.
Avoiding State "Snap"
Directly setting transform.position to the received value will cause jittery movement as network latency fluctuates. Advanced replication techniques involve Interpolation, where the client maintains a small buffer of incoming states. Instead of snapping to the server's position, the client smoothly animates the object from its last known position toward the new server-provided position over time.
By replicating only essential properties and keeping your DTOs lightweight, you minimize bandwidth consumption while maintaining a high level of fidelity. The goal isn't to mirror every internal variable, but to provide enough information for the client to render an accurate approximation of the server’s authoritative logic.
Key Takeaway: State synchronization is the act of periodically broadcasting authoritative data packets to clients, allowing them to interpolate and render a consistent, shared game world without overloading the network.