Performance: Unity Netcode overview
This affects networked game performance, including latency, bandwidth usage, and frame update smoothness.
void Update() {
if (Time.time - lastSendTime > 0.1f) {
SendPositionToServer(transform.position);
lastSendTime = Time.time;
}
}
void SendPositionToServer(Vector3 pos) {
// Sends position updates throttled to 10 times per second
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("UpdatePos", serverClientId, pos);
}void Update() {
SendPositionToServer(transform.position);
}
void SendPositionToServer(Vector3 pos) {
// Sends position every frame without throttling
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("UpdatePos", serverClientId, pos);
}| Pattern | Network Messages | CPU Load | Latency Impact | Verdict |
|---|---|---|---|---|
| Send every frame | High (60+ per second) | High | High latency and jitter | [X] Bad |
| Throttled updates | Low (10 per second) | Low | Low latency, smooth gameplay | [OK] Good |
public class Player : NetworkBehaviour {
public NetworkVariable<int> health = new NetworkVariable<int>(100);
public override void OnNetworkSpawn() {
if (IsServer) {
health.Value -= 10;
}
}
}health.Value on clients after spawning?public class Player : NetworkBehaviour {
public NetworkVariable<int> score = new NetworkVariable<int>();
void Update() {
if (IsClient) {
score.Value += 1;
}
}
}Pass the test and this pattern moves unknown