Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
NetworkVariable
now includes built-in support for NativeHashSet
, NativeHashMap
, List
, HashSet
, and Dictionary
(#2813)NetworkVariable
now includes delta compression for collection values (NativeList
, NativeArray
, NativeHashSet
, NativeHashMap
, List
, HashSet
, Dictionary
, and FixedString
types) to save bandwidth by only sending the values that changed. (Note: For NativeList
, NativeArray
, and List
, this algorithm works differently than that used in NetworkList
. This algorithm will use less bandwidth for "set" and "add" operations, but NetworkList
is more bandwidth-efficient if you are performing frequent "insert" operations.) (#2813)UserNetworkVariableSerialization
now has optional callbacks for WriteDelta
and ReadDelta
. If both are provided, they will be used for all serialization operations on NetworkVariables of that type except for the first one for each client. If either is missing, the existing Write
and Read
will always be used. (#2813)INetworkSerializable
types can perform delta serialization by setting UserNetworkVariableSerialization<T>.WriteDelta
and UserNetworkVariableSerialization<T>.ReadDelta
for those types. The built-in INetworkSerializable
serializer will continue to be used for all other serialization operations, but if those callbacks are set, it will call into them on all but the initial serialization to perform delta serialization. (This could be useful if you have a large struct where most values do not change regularly and you want to send only the fields that did change.) (#2813)NetworkTransform
could not properly synchronize its base position when using half float precision. (#2845)OnClientDisconnectCallback
for its own local client when internally shutting down. (#2822)NetworkObject
s with complex nested children NetworkObject
s (more than one child in depth) would not synchronize properly if WorldPositionStays was set to true. (#2796)NetworkObjectReference
and NetworkBehaviourReference
to allow null references when constructing and serializing. (#2874)NetworkAnimator
no longer requires the Animator
component to exist on the same GameObject
. (#2872)NetworkTransform
to now use NetworkTransformMessage
as opposed to named messages for NetworkTransformState updates. (#2810)CustomMessageManager
so it no longer attempts to register or "unregister" a null or empty string and will log an error if this condition occurs. (#2807)Rpc
. (#2762)
Server
, NotServer
, Owner
, NotOwner
, Me
, NotMe
, ClientsAndHost
, and Everyone
. Runtime overrides are available for any of these targets, as well as for sending to a specific ID or groups of IDs.ServerRpc
and ClientRpc
. ServerRpc
and ClientRpc
remain in their existing forms for backward compatibility, but Rpc
will be the recommended and most supported option.NetworkManager.OnConnectionEvent
as a unified connection event callback to notify clients and servers of all client connections and disconnections within the session (#2762)NetworkManager.ServerIsHost
and NetworkBehaviour.ServerIsHost
to allow a client to tell if it is connected to a host or to a dedicated server (#2762)SceneEventProgress.SceneManagementNotEnabled
return status to be returned when a NetworkSceneManager
method is invoked and scene management is not enabled. (#2735)SceneEventProgress.ServerOnlyAction
return status to be returned when a NetworkSceneManager
method is invoked by a client. (#2735)NetworkObject.InstantiateAndSpawn
and NetworkSpawnManager.InstantiateAndSpawn
methods to simplify prefab spawning by assuring that the prefab is valid and applies any override prior to instantiating the GameObject
and spawning the NetworkObject
instance. (#2710)OnClientDisconnectedCallback
was not being invoked under certain conditions. (#2789)OnClientDisconnectedCallback
was always returning 0 as the client identifier. (#2789)NetworkVariable
or NetworkList
within OnNetworkDespawn
during a shutdown sequence would throw an exception. (#2789)NetworkTransform
was using the NetworkManager.ServerTime.Tick
as opposed to NetworkManager.NetworkTickSystem.ServerTime.Tick
during the authoritative side's tick update where it performed a delta state check. (#2777)LoadSceneMode.Single
, a CreateObjectMessage
could be received, processed, and the resultant spawned NetworkObject
could be instantiated in the client's currently active scene that could, towards the end of the client synchronization or loading process, be unloaded and cause the newly created NetworkObject
to be destroyed (and throw and exception). (#2735)NetworkTransform
instance with interpolation enabled would result in wide visual motion gaps (stuttering) under above normal latency conditions and a 1-5% or higher packet are drop rate. (#2713)NetworkManager.Shutdown
is invoked. This will send a disconnect notification to all connected clients and the server-host will wait for all connected clients to disconnect or timeout after a 5 second period before completing the shutdown process. (#2789)OnClientDisconnectedCallback
will now return the assigned client identifier on the local client side if the client was approved and assigned one prior to being disconnected. (#2789)NetworkTransform.SetState
(and related methods) now are cumulative during a fractional tick period and sent on the next pending tick. (#2777)NetworkManager.ConnectedClientsIds
is now accessible on the client side and will contain the list of all clients in the session, including the host client if the server is operating in host mode (#2762)NetworkSceneManager
to return a SceneEventProgress
status and not throw exceptions for methods invoked when scene management is disabled and when a client attempts to access a NetworkSceneManager
method by a client. (#2735)NetworkTransform
authoritative instance tick registration so a single NetworkTransform
specific tick event update will update all authoritative instances to improve perofmance. (#2713)NetworkPrefabs.OverrideToNetworkPrefab
dictionary is no longer used/populated due to it ending up being related to a regression bug and not allowing more than one override to be assigned to a network prefab asset. (#2710)NetworkObject
s now store their source network prefab asset's GlobalObjectIdHash
internally that is used, when scene management is disabled, by clients to spawn the correct prefab even if the NetworkPrefab
entry has an override. This does not impact dynamically spawning the same prefab which will yield the override on both host and client. (#2710)NetworkObject
s no longer require a NetworkPrefab
entry with GlobalObjectIdHash
override in order for clients to properly synchronize. (#2710)NetworkObject
s now set their IsSceneObject
value when generating their GlobalObjectIdHash
value. (#2710)NetworkConfig.SpawnTimeout
value from 1.0s to 10.0s. (#2710)GenerateSerializationForGenericParameterAttribute
, which can be applied to user-created Network Variable types to ensure the codegen generates serialization for the generic types they wrap. (#2694)GenerateSerializationForTypeAttribute
, which can be applied to any class or method to ensure the codegen generates serialization for the specific provided type. (#2694)NetworkVariableSerialization<T>.Read
, NetworkVariableSerialization<T>.Write
, NetworkVariableSerialization<T>.AreEqual
, and NetworkVariableSerialization<T>.Duplicate
to further support the creation of user-created network variables by allowing users to access the generated serialization methods and serialize generic types efficiently without boxing. (#2694)NetworkVariableBase.MarkNetworkBehaviourDirty
so that user-created network variable types can mark their containing NetworkBehaviour
to be processed by the update loop. (#2694)NetworkSceneManager
instance was not adding the currently active scene to its list of scenes loaded. (#2723)UnityTransport
would attempt to establish WebSocket connections even if using UDP/DTLS Relay allocations when the build target was WebGL. This only applied to working in the editor since UDP/DTLS can't work in the browser. (#2695)NetworkBehaviour
component's OnNetworkDespawn
was not being invoked on the host-server side for an in-scene placed NetworkObject
when a scene was unloaded (during a scene transition) and the NetworkBehaviour
component was positioned/ordered before the NetworkObject
component. (#2685)SpawnWithObservers
was not being honored when NetworkConfig.EnableSceneManagement
was disabled. (#2682)NetworkAnimator
was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674)DefaultNetworkPrefabs
asset was not enabled by default. (#2662)GlobalObjectIdHash
value could be updated but the asset not marked as dirty. (#2662)GlobalObjectIdHash
value of a (network) prefab asset could be assigned an incorrect value when editing the prefab in a temporary scene. (#2662)GlobalObjectIdHash
value generated after creating a (network) prefab from an object constructed within the scene would not be the correct final value in a stand alone build. (#2662)com.unity.transport
to version 1.4.0. (#2716)NetworkClient.OwnedObjects
was not returning any owned objects due to the NetworkClient.IsConnected
not being properly set. (#2631)NetworkTransform
using full precision state updates was losing transform state updates when interpolation was enabled. (#2624)NetworkObject.SpawnWithObservers
was not being honored for late joining clients. (#2623)NetworkManager.Shutdown
multiple times, depending upon the timing, could cause an exception. (#2622)NativeArray<>
and NativeList<>
in FastBufferReader
/FastBufferWriter
, BufferSerializer
, NetworkVariable
, and RPCs. (To use NativeList<>
, add UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
to your Scripting Define Symbols in Project Settings > Player
) (#2375)NetworkObject.SpawnWithObservers
property (default is true) that when set to false will spawn a NetworkObject
with no observers and will not be spawned on any client until NetworkObject.NetworkShow
is invoked. (#2568)OnClientDisconnected
client identifier was incorrect after a pending client connection was denied. (#2569)NetworkListEvent
for EventType.RemoveAt
events. (#2542,#2543)NetworkVariable
s of enum types. (#2529)NetworkVariable
with an INetworkSerializable
type that doesn't meet the new()
constraint will now create a compile-time error instead of an editor crash (#2528)UnityTransport
that occurred if StartClient
failed. (#2518)NetworkObject
(s). (#2510)UnityTransport
dependency on com.unity.transport
to 1.3.4. (#2533)OnServerStarted
and OnServerStopped
events that will trigger only on the server (or host player) to notify that the server just started or is no longer active (#2420)OnClientStarted
and OnClientStopped
events that will trigger only on the client (or host player) to notify that the client just started or is no longer active (#2420)NetworkTransform.UseHalfFloatPrecision
property that, when enabled, will use half float values for position, rotation, and scale. This yields a 50% bandwidth savings a the cost of precision. (#2388)NetworkTransform.UseQuaternionSynchronization
property that, when enabled, will synchronize the entire quaternion. (#2388)NetworkTransform.UseQuaternionCompression
property that, when enabled, will use a smallest three implementation reducing a full quaternion synchronization update to the size of an unsigned integer. (#2388)NetworkTransform.SlerpPosition
property that, when enabled along with interpolation being enabled, will interpolate using Vector3.Slerp
. (#2388)BufferedLinearInterpolatorVector3
that replaces the float version, is now used by NetworkTransform
, and provides the ability to enable or disable Slerp
. (#2388)HalfVector3
used for scale when half float precision is enabled. (#2388)HalfVector4
used for rotation when half float precision and quaternion synchronization is enabled. (#2388)HalfVector3DeltaPosition
used for position when half float precision is enabled. This handles loss in position precision by updating only the delta position as opposed to the full position. (#2388)NetworkTransform.GetSpaceRelativePosition
and NetworkTransform.GetSpaceRelativeRotation
helper methods to return the proper values depending upon whether local or world space. (#2388)NetworkTransform.OnAuthorityPushTransformState
virtual method that is invoked just prior to sending the NetworkTransformState
to non-authoritative instances. This provides users with the ability to obtain more precise delta values for prediction related calculations. (#2388)NetworkTransform.OnNetworkTransformStateUpdated
virtual method that is invoked just after the authoritative NetworkTransformState
is applied. This provides users with the ability to obtain more precise delta values for prediction related calculations. (#2388)NetworkTransform.OnInitialize
virtual method that is invoked after the NetworkTransform
has been initialized or re-initialized when ownership changes. This provides for a way to make adjustments when NetworkTransform
is initialized (i.e. resetting client prediction etc) (#2388)NetworkObject.SynchronizeTransform
property (default is true) that provides users with another way to help with bandwidth optimizations where, when set to false, the NetworkObject
's associated transform will not be included when spawning and/or synchronizing late joining players. (#2388)NetworkSceneManager.ActiveSceneSynchronizationEnabled
property, disabled by default, that enables client synchronization of server-side active scene changes. (#2383)NetworkObject.ActiveSceneSynchronization
, disabled by default, that will automatically migrate a NetworkObject
to a newly assigned active scene. (#2383)NetworkObject.SceneMigrationSynchronization
, enabled by default, that will synchronize client(s) when a NetworkObject
is migrated into a new scene on the server side via SceneManager.MoveGameObjectToScene
. (#2383)CheckObjectVisibility
delegate is checked and applied, upon NetworkShow
attempt. Found while supporting (#2454), although this is not a fix for this (already fixed) issue. (#2463)NetworkTransform
authority handles delta checks on each new network tick and no longer consumes processing cycles checking for deltas for all frames in-between ticks. (#2388)NetworkTransformState
structure is now public and now has public methods that provide access to key properties of the NetworkTransformState
structure. (#2388)NetworkTransform
interpolation adjusts its interpolation "ticks ago" to be 2 ticks latent if it is owner authoritative and the instance is not the server or 1 tick latent if the instance is the server and/or is server authoritative. (#2388)NetworkSceneManager
to migrate dynamically spawned NetworkObject
s with DestroyWithScene
set to false into the active scene if their current scene is unloaded. (#2383)NetworkSceneManager.ClientSynchronizationMode
during the initial client synchronization. (#2383)NetworkAnimator
was building client RPC parameters to exclude the host from sending itself messages but was not including it in the ClientRpc parameters. (#2492)NetworkAnimator
was not properly detecting and synchronizing cross fade initiated transitions. (#2481)NetworkAnimator
was not properly synchronizing animation state updates. (#2481)NetworkVariable
s in derived NetworkBehaviour
s (#2423)Animator
properties to AnimationCurve
s would cause NetworkAnimator
to attempt to update those changes. (#2416)NetworkAnimator
would not check if its associated Animator
was valid during serialization and would spam exceptions in the editor console. (#2416)NetworkTransform
. Now using half precision or full quaternion synchronization will always update all axis. (#2388)NetworkTransform
was not setting the teleport flag when the NetworkTransform.InLocalSpace
value changed. This issue only impacted NetworkTransform
when interpolation was enabled. (#2388)NetworkSceneManager.ClientSynchronizationMode
is LoadSceneMode.Additive
and the server changes the currently active scene prior to a client connecting then upon a client connecting and being synchronized the NetworkSceneManager would clear its internal ScenePlacedObjects list that could already be populated. (#2383)NetworkSceneManager.ClientSynchronizationMode
was set to LoadSceneMode.Additive
. (#2383)UnityTransport
dependency on com.unity.transport
to 1.3.3. (#2450)NetworkShow()
of NetworkObject
s are delayed until the end of the frame to ensure consistency of delta-driven variables like NetworkList
.NetworkObject
are reset at end-of-frame and not at serialization time.NetworkHide()
of an object that was just NetworkShow()
n produces a warning, as remote clients will not get a spawn/despawn pair.shouldGhostsInterpolate
to teleportDisabled
for better clarity of what that parameter does. (#2228)NetworkManager.LocalClientId
was returning the NetworkTransport.ServerClientId
as opposed to the NetworkManager.m_LocalClientId
. (#2398)NetworkObject
parented under an in-scene placed NetworkObject
would have its InScenePlaced
value changed to true
. This would result in a soft synchronization error for late joining clients. (#2396)NetcodeSettingsProvider
would throw an exception in Unity 2020.3.x versions. (#2345)UnityTransport
where an exception would be thrown if starting a Relay host/server on WebGL. This exception should only be thrown if using direct connections (where WebGL can't act as a host/server). (#2321)NetworkAnimator
issue where it was not checking for AnimatorStateTtansition.destinationStateMachine
and any possible sub-states defined within it. (#2309)NetworkAnimator
issue where the host client was receiving the ClientRpc animation updates when the host was the owner.(#2309) Will be fixed in next update
NetworkAnimator
issue with using pooled objects and when specific properties are cleaned during despawn and destroy.(#2309)NetworkAnimator
was checking for animation changes when the associated NetworkObject
was not spawned.(#2309)