0
0
Unityframework~8 mins

State synchronization in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: State synchronization
HIGH IMPACT
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.
Synchronizing player position and actions in a multiplayer game
Unity
void Update() {
  if (HasStateChanged()) {
    SendDeltaStateToClients(); // only send changed data
  }
}
Sending only changed data reduces network bandwidth and CPU load, improving responsiveness.
📈 Performance Gainreduces network usage by 80%, lowers CPU spikes, improves frame rate stability
Synchronizing player position and actions in a multiplayer game
Unity
void Update() {
  SendFullStateToAllClients(); // sends entire player state every frame
}
Sending full state every frame causes excessive network traffic and CPU usage, leading to lag and dropped frames.
📉 Performance Costblocks rendering for 50+ ms per frame on slow networks, triggers high CPU usage
Performance Comparison
PatternNetwork UsageCPU LoadFrame ImpactVerdict
Send full state every frameVery highHighCauses frame drops and lag[X] Bad
Send only changed state with throttlingLowLowSmooth frame rate and responsive input[OK] Good
Rendering Pipeline
State synchronization impacts the game loop by adding network communication and state updates before rendering each frame. Excessive or inefficient synchronization delays input processing and frame rendering.
Game Logic Update
Network Communication
Rendering
⚠️ BottleneckNetwork Communication and Game Logic Update due to heavy data processing
Core Web Vital Affected
INP
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.
Optimization Tips
1Send only changed state data, not full state every frame.
2Limit synchronization frequency to balance smoothness and performance.
3Use Unity Profiler to monitor network and CPU impact of synchronization.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance problem with sending the full player state every frame in Unity multiplayer?
AIt causes excessive network traffic and CPU load, leading to lag.
BIt improves input responsiveness by sending more data.
CIt reduces CPU usage by batching updates.
DIt decreases network usage by compressing data.
DevTools: Unity Profiler
How to check: Open Unity Profiler, record gameplay session, check Network and CPU usage graphs during state sync calls.
What to look for: Look for spikes in CPU and network usage during synchronization; lower and stable usage indicates good performance.