UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

optimization

[Netcode] Tame Lag from Projectile Network Data

Under Audit

networkingoptimizationmultiplayerphysics

Unity 2022.3.x - Unity 6.0.x

Published Tue, Mar 17

When many projectiles are active, constant Transform synchronization can lead to significant network overhead and perceived lag. The goal is to reduce network data by sending only initial projectile states and relying on client-side extrapolation.

Issue

 A common challenge in multiplayer games involves managing network data for numerous active projectiles. When projectiles are configured with physics body components and move through the environment, their Transform data is often synchronized every snapshot by default. This behavior is expected in server-authoritative setups where Transform changes occur each tick. However, when a large number of projectiles are simultaneously 'in the air', the constant transmission of their changing positions can overwhelm network bandwidth. This leads to the server occasionally skipping data for some projectiles, causing them to appear laggy or unsynchronized on client machines. Increasing the network importance of projectiles may resolve their lag but can subsequently cause other entities to suffer from similar synchronization issues. Since many projectiles do not change direction, scale, or speed after their initial launch, it is desirable for the server to only communicate their initial spawn state and subsequent destruction. Clients should be able to accurately extrapolate the projectile's movement based on this initial data. Simply reducing the snapshot frequency for projectiles is not a viable solution, as this also delays the reporting of their initial spawn, negatively impacting user experience.

Experimental Fixes
  • Implement a custom network synchronization strategy for projectiles that only transmits their initial spawn state (position, velocity, direction) and destruction events, allowing clients to extrapolate movement.
  • Utilize network interest management systems to define when specific projectiles are relevant to individual clients, thereby reducing unnecessary data transmission for distant or less critical entities.
  • Explore options within your chosen networking solution (e.g., Netcode for GameObjects) to override default NetworkTransform behavior for projectiles, enabling more granular control over which Transform properties are synchronized and at what frequency.

Editor's Note:

The above fixes have not been verified by our audit team yet. They are provided exclusively for your own technical research. We recommend creating a backup of your project before proceeding with any attempts. Utilize at your own discretion!

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.