Performance: State synchronization
State synchronization affects the smoothness and responsiveness of multiplayer game experiences by controlling how often and how much data is sent and updated across clients and servers.
void Update() {
if (HasStateChanged()) {
SendDeltaStateToClients(); // only send changed data
}
}void Update() {
SendFullStateToAllClients(); // sends entire player state every frame
}| Pattern | Network Usage | CPU Load | Frame Impact | Verdict |
|---|---|---|---|---|
| Send full state every frame | Very high | High | Causes frame drops and lag | [X] Bad |
| Send only changed state with throttling | Low | Low | Smooth frame rate and responsive input | [OK] Good |
public NetworkVariable<Vector3> playerPosition = new NetworkVariable<Vector3>(Vector3.zero);
void UpdatePosition(Vector3 newPos) {
if (IsOwner) {
playerPosition.Value = newPos;
}
Debug.Log(playerPosition.Value);
}public NetworkVariable<int> score = new NetworkVariable<int>(0);
void UpdateScore(int points) {
score.Value += points;
}Pass the test and this pattern moves unknown