0
0
Unityframework~8 mins

Remote procedure calls in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: Remote procedure calls
MEDIUM IMPACT
Remote procedure calls affect network latency and responsiveness in multiplayer or distributed Unity applications.
Sending frequent updates for player position in a multiplayer game
Unity
void Update() {
  if (Time.time - lastSent > 0.1f) {
    CmdSendPosition(transform.position);
    lastSent = Time.time;
  }
}

[Command]
void CmdSendPosition(Vector3 pos) {
  RpcUpdatePosition(pos);
}

[ClientRpc]
void RpcUpdatePosition(Vector3 pos) {
  transform.position = pos;
}
Limits RPC calls to 10 times per second, reducing network load.
📈 Performance GainReduces network traffic by 90%, improving responsiveness.
Sending frequent updates for player position in a multiplayer game
Unity
void Update() {
  CmdSendPosition(transform.position);
}

[Command]
void CmdSendPosition(Vector3 pos) {
  RpcUpdatePosition(pos);
}

[ClientRpc]
void RpcUpdatePosition(Vector3 pos) {
  transform.position = pos;
}
Sending RPC every frame causes excessive network traffic and delays.
📉 Performance CostTriggers high network latency and bandwidth usage, causing input lag.
Performance Comparison
PatternNetwork CallsLatency ImpactBandwidth UsageVerdict
Send RPC every frameHigh (60+ per second)High latency and lagHigh bandwidth usage[X] Bad
Send RPC at fixed intervalsLow (10 per second)Lower latencyReduced bandwidth usage[OK] Good
Rendering Pipeline
RPCs do not directly affect rendering but impact game responsiveness by delaying state updates across clients.
Network Transmission
Game State Update
Rendering indirectly
⚠️ BottleneckNetwork Transmission latency
Optimization Tips
1Avoid sending RPCs every frame; use fixed intervals instead.
2Keep RPC payloads as small as possible to reduce bandwidth.
3Use Unity's Network Profiler to monitor and optimize RPC usage.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance issue with sending RPCs every frame in Unity multiplayer?
AIt causes excessive network traffic and latency.
BIt increases CPU usage on the client only.
CIt reduces the frame rate of the local player.
DIt causes memory leaks in the game.
DevTools: Network Profiler
How to check: Open Unity Profiler, select Network section, and monitor RPC call frequency and data size during gameplay.
What to look for: Look for high RPC call counts and large payloads causing spikes in network usage.