Skip to main content

NetworkTransform

The position, rotation, and scale of a NetworkObject is normally only synchronized once when that object is spawned. To synchronize position, rotation, and scale at realtime during the game, a NetworkTransform component is needed. NetworkTransform synchronizes the transform from server object to the clients.

NetworkTransform covers most use cases for synchronizing transforms. For some special cases such as really fast paced games a custom implementation with a different interpolation algorithm might be better.

tip

You can have multiple NetworkTransform components on child objects of your network object to synchronize individual positions of child objects.

Restricting Synchronization#

Quite often not all transform values of a GameObject need to be synchronized over the network. For instance if the scale of the GameObject never changes it can be deactivated in the syncing scale row in the inspector. Currently deactivating synchronization only saves on CPU costs but in the future it will also reduce the bandwidth used by NetworkTransform`.

Thresholds#

The threshold values can be used to set a minimum threshold value. Changes to position, rotation or scale below the threshold will not be synchronized That way minor changes to a value will not trigger a position synchronization which can help to reduce bandwidth.

note

Many small changes below the threshold will still result in a synchronization of the values as soon as all the accumulative changes cross the threshold.

Local Space#

By default NetworkTransform synchronizes the transform of an object in world space. The In Local Space configuration option allows to switch to synchronizing the transform in local space instead.

Using local space can improve the synchronization of the transform when the object gets re-parented because the re-parenting will not change the local space transform of the object but would modify the global space position.

Interpolation#

Check the Interpolate setting to enabled interpolation. Interpolation is enabled by default and is highly recommended. With interpolation enabled the NetworkTransform smoothly interpolates incoming changes to position, rotation and scale. In addition interpolation buffers the incoming data with a slight delay and applies additional smoothing to the values. All these factors combined result in a much smoother transform synchronization.

When Interpolate is disabled changes to the transform are applied immediately resulting in a less smooth position and more jitter.

Example banner
Graphic of a buffered tick between the server and a client (i.e. interpolation)

ClientNetworkTransform#

NetworkTransform always synchronizes positions from the server to the clients and position changes on the clients are not allowed. Netcode for GameObjects comes with a sample containing a ClientNetworkTransform. This transform synchronizes the position of the owner client to the server and all other client allowing for client authoritative gameplay.

To install the ClientNetworkTransform sample into your project open the Package Manager window in the Unity Editor and select the Netcode for GameObjects package. In the description of the package you can find a list of package samples. Press the Install button next to the ClientNetworkTransform sample to install it into your existing Unity project.