diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs index 7f95289319..c3d7245540 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs @@ -286,7 +286,18 @@ internal string GenerateObserverErrorMessage(ClientRpcParams clientRpcParams, ul /// Gets the NetworkManager that owns this NetworkBehaviour instance /// See note around `NetworkObject` for how there is a chicken / egg problem when we are not initialized /// - public NetworkManager NetworkManager => NetworkObject.NetworkManager; + public NetworkManager NetworkManager + { + get + { + if (NetworkObject?.NetworkManager != null) + { + return NetworkObject?.NetworkManager; + } + + return NetworkManager.Singleton; + } + } /// /// If a NetworkObject is assigned, it will return whether or not this NetworkObject @@ -349,9 +360,16 @@ public NetworkObject NetworkObject { get { - if (m_NetworkObject == null) + try + { + if (m_NetworkObject == null) + { + m_NetworkObject = GetComponentInParent(); + } + } + catch (Exception) { - m_NetworkObject = GetComponentInParent(); + return null; } // ShutdownInProgress check: