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.
You can have multiple
NetworkTransform components on child objects of your network object to synchronize individual positions of child objects.
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`.
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.
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.
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.
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.
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.
Interpolate is disabled changes to the transform are applied immediately resulting in a less smooth position and more jitter.
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.