Netcode for Gameobjects 2.4.0 released

:package: Netcode for GameObjects v2.4.0 is now publicly available! :package:

Crack your knuckles and get ready for another Netcode for GameObjects update! The v2.4.0 update includes a wide range of fixes along with the added SingelPlayerTransport that allows you to run a single player hosted session without any need for a lower-layer transport. NetworkObject , NetworkBehaviour , and NetworkVariable serialization sizes were all increased from ushort.maxvalue to int.maxvalue . The distributed authority network topology’s connection sequence has been improved to resolve some known initial client synchronization related issues.

Happy Netcoding!

Fixed
  • Fixed issue where the NetworkObject.DontDestroyWithOwner was not being honored.
  • Fixed issue where non-authority NetworkTransform instances would not allow non-synchronized axis values to be updated locally.
  • Fixed issue where invoking NetworkObject.NetworkShow and NetworkObject.ChangeOwnership consecutively within the same call stack location could result in an unnecessary change in ownership error message generated on the target client side.
  • Fixed issue where NetworkVariables on a NetworkBehaviour could fail to synchronize changes if one has NetworkVariableUpdateTraits set and is dirty but is not ready to send.
  • Fixed issue with the Distributed Authority connection sequence with scene management enabled where the ClientConnected event was fired before the client was synchronized.
  • Fixed inconsistencies in the OnSceneEvent callback.
  • Fixed issues with the NetworkBehaviour and NetworkVariable length safety checks.
  • Fixed memory leaks when domain reload is disabled.
  • Fixed issue where disabling the physics or physics2D package modules could result in a compilation error.
  • Fixed an exception being thrown when unregistering a custom message handler from within the registered callback.
Added
  • Added SinglePlayerTransport that provides the ability to start as a host for a single player network session.
  • When using UnityTransport >=2.4 and Unity >= 6000.1.0a1, SetConnectionData will accept a fully qualified hostname instead of an IP as a connect address on the client side.
2 Likes

Looks like this update broke connection flow in my project.

The client receives the following error in SynchronizeNetworkObjects:

KeyNotFoundException: The given key '-98622' was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <314938d17f3848e8ac683e11b27f62ee>:0)
Unity.Netcode.NetworkSceneManager.SynchronizeNetworkObjects (System.UInt64 clientId, System.Boolean synchronizingService) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/SceneManagement/NetworkSceneManager.cs:2018)
Unity.Netcode.ConnectionApprovedMessage.Handle (Unity.Netcode.NetworkContext& context) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/Messages/ConnectionApprovedMessage.cs:259)
Unity.Netcode.NetworkMessageManager.ReceiveMessage[T] (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.NetworkMessageManager manager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:563)
Unity.Netcode.NetworkMessageManager.HandleMessage (Unity.Netcode.NetworkMessageHeader& header, Unity.Netcode.FastBufferReader reader, System.UInt64 senderId, System.Single timestamp, System.Int32 serializedHeaderSize) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:422)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.NetworkMessageManager:HandleMessage(NetworkMessageHeader&, FastBufferReader, UInt64, Single, Int32) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:426)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue() (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:448)
Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkManager.cs:340)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:214)

The session owner gets this error message as the client connects:

You cannot start a host when connecting to a distributed authority CMB Service!
UnityEngine.Debug:LogError (object)
Unity.Netcode.NetworkClient:SetRole (bool,bool,Unity.Netcode.NetworkManager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Connection/NetworkClient.cs:94)
Unity.Netcode.NetworkConnectionManager:AddClient (ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Connection/NetworkConnectionManager.cs:1013)
Unity.Netcode.NetworkSceneManager:HandleSessionOwnerEvent (uint,ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/SceneManagement/NetworkSceneManager.cs:2465)
Unity.Netcode.NetworkSceneManager:HandleSceneEvent (ulong,Unity.Netcode.FastBufferReader) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/SceneManagement/NetworkSceneManager.cs:2664)
Unity.Netcode.SceneEventMessage:Handle (Unity.Netcode.NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/Messages/SceneEventMessage.cs:29)
Unity.Netcode.NetworkMessageManager:ReceiveMessage<Unity.Netcode.SceneEventMessage> (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.NetworkMessageManager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:563)
Unity.Netcode.NetworkMessageManager:HandleMessage (Unity.Netcode.NetworkMessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:422)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Messaging/NetworkMessageManager.cs:448)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkManager.cs:340)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:214)

This happens in NetworkSceneManager as I have enabled automatic scene management. Once I get this set of errors, my logs are then followed by on the session owner and the client:

Internal: JobTempAlloc has allocations that are more than the maximum lifespan of 4 frames old - this is not allowed and likely a leak

Additionally, after this set of exceptions, the client then receives more errors + warnings:

Detected DAHost mode. This is an unsupported configuration. Falling back to ClientServer. Please start Distributed Authority mode as client.
UnityEngine.Debug:LogWarning (object)
Unity.Services.DistributedAuthority.DistributedAuthorityTransport:OnCurrentTopology () (at ./Library/PackageCache/com.unity.services.multiplayer@e9296dd42336/Runtime/DistributedAuthority/SDK/DistributedAuthorityTransport.cs:25)
Unity.Netcode.NetworkTransport:CurrentTopology () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Transports/NetworkTransport.cs:165)
Unity.Netcode.NetworkManager:UpdateTopology () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkManager.cs:307)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkManager.cs:329)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:214)

[Session-Owner Sender=0] [Topology Mismatch] Transport detected an issue with the topology (ClientServer | DistributedAuthority) usage or setting! Disconnecting from session.
UnityEngine.Debug:LogError (object)
Unity.Netcode.NetworkLog:LogErrorServerLocal (string,ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Logging/NetworkLog.cs:129)
Unity.Netcode.NetworkLog:LogServer (string,Unity.Netcode.NetworkLog/LogType) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Logging/NetworkLog.cs:94)
Unity.Netcode.NetworkLog:LogErrorServer (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Logging/NetworkLog.cs:58)
Unity.Netcode.NetworkManager:UpdateTopology () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkManager.cs:310)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkManager.cs:329)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@9684ced5879f/Runtime/Core/NetworkUpdateLoop.cs:214)

I’ve added a couple of log messages to UpdateServerClientSceneHandle to see when the scene handle mappings get populated and it looks the ClientSceneHandleToServerSceneHandle is populated too late (its populated right after this exception), which leads me to believe that scenes are now synchronized too late or incorrectly.

The way I reproduced this in my project (Scene 1 in this case is my bootstrap scene, always loaded after the game starts):

  • Client A starts a Session A in (Scene 1, Scene 2 (additive, active)).
  • Client B starts a Session B in (Scene 1, Scene 3 (additive, active)).
  • Client B leaves Session B and starts loading another set of scenes (Scene 1, Scene 2 (additive, active)).
  • Right after the scenes are finished loading, Client B starts joining Session A.
  • Client B gets KeyNotFoundException log message.
  • Client A (session owner) gets CMB Services log message.
  • The network session is in broken state where Client B sees Client A (session owner) locked in place and Client A doesn’t see Client B.

Some details:

  • Unity 6000.0.47f1.
  • Multiplayer Play mode 1.3.3.
  • Using sessions API.
  • I did not update any other packages prior to trying out v2.4.0.
  • Distributed Authority.
  • Session owner uses CreateSessionAsync.
  • Client uses QuerySessionsAsync and then passes the id to CreateOrJoinSessionAsync.

This issue was discovered just shortly after v2.4.0 was made public and has a pending fix for it in PR-3486. The fix for this will be released in a patch soon. The memory leak itself is roughly the size of a ulong * number of connected clients. So, it is a relatively small leak that happens once per non-session owner connecting to an existing session…but will be resolved very soon.

The other issue I am looking into today.

1 Like

I believe PR-3491 should resolve this issue.

If you have time, try using this branch and see if it resolves the issue on your side?

 "com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#fix/reset-networkclient-completely-upon-shutdown",

This will be included in an up-and-coming patch.

1 Like

Just tested this now, I can confirm that the bug I mentioned earlier, including the warnings related to leaks are no longer there!

1 Like

Thank you for providing the issue and for verifying the fix on your end.
It is much appreciated!

These fixes will follow the pending v2.4.1 update (primarily internal house keeping adjustments) most likely as v2.4.2 (exact version TBD).

Hey, as a follow up, NGOv2.4.2 is already released (CHANGELOG) which contains all the fixes mentioned before in the thread.

We would also like to point out that NGOv2.4.1 (CHANGELOG) contained a bunch of structure updates so remember that if you are utilizing TestHelpers then follow the instruction from the CHANGELOG

If your project is using the Unity.Netcode.TestHelpers.Runtime assembly then you need to switch asmdef references to Unity.Netcode.Runtime.Tests .

Happy Netcoding!

Quick mention that NGOv2.4.3 was released as a response to issue reported HERE :backhand_index_pointing_left: