From 3bd96747545f0b79bc3306452621c2d79481d1ea Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 2 Nov 2026 10:47:23 -0500 Subject: [PATCH 1/7] fix: handle NetworkManager Awake being overridden (cherry picked from commit e6693e90ccf3f0dc68e2626de3bfda3ad27d072d) --- .../Runtime/Core/NetworkManager.cs | 27 ++++++++++-- .../Tests/Runtime/NetworkManagerTests.cs | 41 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index fa3e886dc5..5b28822596 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -1100,7 +1100,7 @@ public void SetSingleton() OnSingletonReady?.Invoke(); } - private void Awake() + protected virtual void Awake() { if (Log == null) { @@ -1124,7 +1124,7 @@ private void Awake() } } - private void OnEnable() + protected virtual void OnEnable() { if (RunInBackground) { @@ -1485,6 +1485,11 @@ private void UnifiedApplyNetcodeConfig() /// returns true if started in server mode successfully; otherwise false public bool StartServer() { + if (Log == null) + { + Log = new ContextualLogger(this, false); + Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); + } Log.CaptureFunctionCall(); if (!CanStart(StartType.Server)) @@ -1578,6 +1583,11 @@ internal bool InternalStartServer() /// (/) returns true if started in client mode successfully. public bool StartClient() { + if (Log == null) + { + Log = new ContextualLogger(this, false); + Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); + } Log.CaptureFunctionCall(); if (!CanStart(StartType.Client)) @@ -1663,6 +1673,11 @@ internal bool InternalStartClient() /// (/) returns true if started in host mode successfully. public bool StartHost() { + if (Log == null) + { + Log = new ContextualLogger(this, false); + Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); + } Log.CaptureFunctionCall(); if (!CanStart(StartType.Host)) @@ -2017,7 +2032,7 @@ private void OnApplicationQuit() private bool m_IsDestroyed = false; // Note that this gets also called manually by OnSceneUnloaded and OnApplicationQuit - private void OnDestroy() + protected virtual void OnDestroy() { if (m_IsDestroyed) { @@ -2025,6 +2040,12 @@ private void OnDestroy() } m_IsDestroyed = true; + if (Log == null) + { + Log = new ContextualLogger(this, false); + Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); + } + try { ShutdownInternal(); diff --git a/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs index ccf46cb61c..e1262bd920 100644 --- a/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs @@ -198,4 +198,45 @@ private void OnServerStopped(bool obj) m_ServerNetworkManager.Shutdown(); } } + + internal class DerivedNetworkManagerTests + { + private class TestNetworkManager : NetworkManager + { + public void Awake() { } + public void OnEnable() { } + } + + [UnityTest] + public IEnumerator ValidateDerivedNetworkManager() + { + var gameObject = new GameObject("TestNetworkManager"); + var server = gameObject.AddComponent(); + var mockTransport = server.gameObject.AddComponent(); + server.NetworkConfig ??= new NetworkConfig(); + server.NetworkConfig.NetworkTransport = mockTransport; + var client = Object.Instantiate(server); + + var isListening = server.StartServer(); + Assert.That(isListening, Is.True, "Server failed to start!"); + + client.StartClient(); + + var timeoutHelper = new TimeoutHelper(); + yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => client.IsListening, timeoutHelper); + Assert.That(timeoutHelper.TimedOut, Is.False, "Client timed out waiting to connect!"); + + Object.Destroy(client.gameObject); + + server.Shutdown(); + timeoutHelper = new TimeoutHelper(); + yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => !server.IsListening, timeoutHelper); + Assert.That(timeoutHelper.TimedOut, Is.False, "Timed out waiting for server to shutdown!"); + + isListening = server.StartHost(); + Assert.That(isListening, Is.True, "Host failed to start!"); + + Object.Destroy(gameObject); + } + } } From e0bc4f99dc82bab4b23151c44bc6217a8efac1b2 Mon Sep 17 00:00:00 2001 From: Emma Date: Tue, 3 Nov 2026 09:57:12 -0500 Subject: [PATCH 2/7] Fix the XML doc and the double destroy (cherry picked from commit 6f907edebda2df77ddf0d4f07db459d8ec273e7e) --- .../Runtime/Core/NetworkManager.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 5b28822596..19d643c133 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -1100,6 +1100,13 @@ public void SetSingleton() OnSingletonReady?.Invoke(); } + /// + /// Unity calls Awake when loading an instance of a script component. + /// + /// + /// Override this method to implement custom initialization logic for a derived . + /// Ensure you call base.Awake() in your override to allow the base initialization to happen. + /// protected virtual void Awake() { if (Log == null) @@ -1124,6 +1131,13 @@ protected virtual void Awake() } } + /// + /// Called when a component of an active GameObject is first enabled. + /// + /// + /// Override this method to implement custom initialization logic for a derived . + /// Ensure you call base.OnEnable() in your override to allow the base initialization to happen. + /// protected virtual void OnEnable() { if (RunInBackground) @@ -2031,8 +2045,22 @@ private void OnApplicationQuit() private bool m_IsDestroyed = false; - // Note that this gets also called manually by OnSceneUnloaded and OnApplicationQuit + /// + /// Called when a GameObject or component is about to be destroyed. + /// + /// + /// Override this method to implement custom teardown logic for a derived . + /// Ensure you call base.OnDestroy() in your override to allow the base teardown to happen. + /// protected virtual void OnDestroy() + { + DestroyInternal(); + } + + // Internal destroy method that can't be overridden by derived classes. + // Note that this gets also called manually by OnSceneUnloaded and OnApplicationQuit + private void DestroyInternal() + { { if (m_IsDestroyed) { From 4ff2a1182209de25e69a70624c8f3c8dcc6fccf9 Mon Sep 17 00:00:00 2001 From: Emma Date: Tue, 3 Nov 2026 10:17:24 -0500 Subject: [PATCH 3/7] Fix malformed XML doc and simplify logger API (cherry picked from commit ddc074eda181e2ded8c16f10d6b34dd62b9f7d63) --- .../Runtime/Core/NetworkManager.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 19d643c133..df199921da 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -1106,12 +1106,12 @@ public void SetSingleton() /// /// Override this method to implement custom initialization logic for a derived . /// Ensure you call base.Awake() in your override to allow the base initialization to happen. - /// + /// protected virtual void Awake() { if (Log == null) { - Log = new ContextualLogger(this, false); + Log = new ContextualLogger(this); } NetworkConfig?.InitializePrefabs(); @@ -1501,7 +1501,7 @@ public bool StartServer() { if (Log == null) { - Log = new ContextualLogger(this, false); + Log = new ContextualLogger(this); Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); } Log.CaptureFunctionCall(); @@ -1599,7 +1599,7 @@ public bool StartClient() { if (Log == null) { - Log = new ContextualLogger(this, false); + Log = new ContextualLogger(this); Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); } Log.CaptureFunctionCall(); @@ -1689,7 +1689,7 @@ public bool StartHost() { if (Log == null) { - Log = new ContextualLogger(this, false); + Log = new ContextualLogger(this); Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); } Log.CaptureFunctionCall(); @@ -1877,7 +1877,7 @@ private void OnSceneUnloaded(Scene scene) { if (gameObject != null && scene == gameObject.scene) { - OnDestroy(); + DestroyInternal(); } } @@ -2020,7 +2020,7 @@ internal void ShutdownInternal() } } - // Ensures that the NetworkManager is cleaned up before OnDestroy is run on NetworkObjects and NetworkBehaviours when quitting the application. + // Ensures that the NetworkManager is cleaned up before DestroyInternal is run on NetworkObjects and NetworkBehaviours when quitting the application. private void OnApplicationQuit() { // Abrupt shutdown (or immediate exit of play mode). @@ -2034,7 +2034,7 @@ private void OnApplicationQuit() { return; } - OnDestroy(); + DestroyInternal(); #if UNITY_EDITOR if (Singleton != null) { @@ -2070,7 +2070,7 @@ private void DestroyInternal() if (Log == null) { - Log = new ContextualLogger(this, false); + Log = new ContextualLogger(this); Log.Warning(new Context(LogLevel.Normal, "No logger defined. Ensure base.Awake() and base.OnEnable is called in any derived NetworkManager classes.")); } @@ -2169,7 +2169,7 @@ internal void OnValidate() if (Log == null) { - Log = new ContextualLogger(this, false); + Log = new ContextualLogger(this); } // Do a validation pass on NetworkConfig properties From 98fe4c83a2b49fef0625b9b7fed0cca05a665cbf Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 5 Nov 2026 11:11:54 -0500 Subject: [PATCH 4/7] dotnet-fix (cherry picked from commit 5fe1822cf6e7de2cc542fa14e4bd0d7fb6da2c9a) --- testproject/Assets/Tests/Runtime/NetworkManagerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs index e1262bd920..5dd74a95ba 100644 --- a/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkManagerTests.cs @@ -223,14 +223,14 @@ public IEnumerator ValidateDerivedNetworkManager() client.StartClient(); var timeoutHelper = new TimeoutHelper(); - yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => client.IsListening, timeoutHelper); + yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => client.IsListening, timeoutHelper); Assert.That(timeoutHelper.TimedOut, Is.False, "Client timed out waiting to connect!"); Object.Destroy(client.gameObject); server.Shutdown(); timeoutHelper = new TimeoutHelper(); - yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => !server.IsListening, timeoutHelper); + yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => !server.IsListening, timeoutHelper); Assert.That(timeoutHelper.TimedOut, Is.False, "Timed out waiting for server to shutdown!"); isListening = server.StartHost(); From bcb9486bf9cc8844a9a1d50f781a2f3a65468836 Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 5 Nov 2026 17:28:45 -0500 Subject: [PATCH 5/7] Bump to minor version due to new API --- com.unity.netcode.gameobjects/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/package.json b/com.unity.netcode.gameobjects/package.json index 3494748360..9d3100e1cf 100644 --- a/com.unity.netcode.gameobjects/package.json +++ b/com.unity.netcode.gameobjects/package.json @@ -2,7 +2,7 @@ "name": "com.unity.netcode.gameobjects", "displayName": "Netcode for GameObjects", "description": "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.", - "version": "3.2.1", + "version": "3.3.0", "unity": "6000.7", "unityRelease": "0b8", "dependencies": { @@ -17,4 +17,4 @@ "path": "Samples~/Bootstrap" } ] -} \ No newline at end of file +} From 5ced8670f54b7ce34dc3b4db2655c5a03deaef7e Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 5 Nov 2026 17:32:35 -0500 Subject: [PATCH 6/7] Update CHANGELOG --- com.unity.netcode.gameobjects/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 4a03809c92..06327de75f 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -18,6 +18,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed +- Fixed a NullReferenceException that would be thrown if a MonoBehaviour derived from NetworkManager defines it's own Awake or OnEnable. (#4244) - Ensured a useful and human readable error is logged when a NetworkVariable is trying to serialize a private or protected type. (#4239) - Issue where `NetworkAnimator` logged an error for a trigger-conditioned transition into an Exit node, and a client that joined during that transition, or during one into a sub-state machine, did not synchronize with it. Transitions that pass through Exit, Entry or sub-state machine nodes now resolve to the state they reach, and a late-joining client cross-fades from the matching originating state when several states transition into the same destination. (#4238) - Ensured all callbacks are wrapped with exception handling to avoid silent errors. (#4161) From 7e10f31dce003812ef9fe608f3fb7fe4f785f607 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 6 Nov 2026 14:12:16 -0500 Subject: [PATCH 7/7] Fix compilation error --- com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index df199921da..6806d7d56a 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -2060,7 +2060,6 @@ protected virtual void OnDestroy() // Internal destroy method that can't be overridden by derived classes. // Note that this gets also called manually by OnSceneUnloaded and OnApplicationQuit private void DestroyInternal() - { { if (m_IsDestroyed) {