This error occurs infinitely on the client after they leave the game while their player object is destroyed.
MissingReferenceException: The object of type 'Unity.Netcode.NetworkObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <84f0d810adef4e6c8deab33e4ae93f7c>:0) UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <84f0d810adef4e6c8deab33e4ae93f7c>:0) UnityEngine.Component.get_gameObject () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0) Unity.Netcode.NetworkObject.UpdateForSceneChanges () (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkObject.cs:3318) Unity.Netcode.NetworkObject.UpdateNetworkObjectSceneChanges () (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkObject.cs:3287) Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkManager.cs:404) Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkUpdateLoop.cs:191) Unity.Netcode.NetworkUpdateLoop+NetworkPostLateUpdate+<>c.<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@f2477a6c90fe/Runtime/Core/NetworkUpdateLoop.cs:286)
Is there any script attached to the playerObjects? Could you share related code?
1 Like
There is, but I’m confused how the script on the player object could impact this error since it has to do with the Network Manager and Network Object scripts, wouldn’t the attached script be included in the error?
Any updates on this?
I’ve tried debugging the NetworkObject script and somehow the gameObject attached is giving the missing reference exception. How can this run if there is no attached game object?
internal void UpdateForSceneChanges()
{
Debug.Log(SceneMigrationSynchronization);
Debug.Log(IsSpawned);
Debug.Log(NetworkManager == null);
Debug.Log(NetworkManager.ShutdownInProgress);
Debug.Log(NetworkManager.NetworkConfig.EnableSceneManagement);
Debug.Log(IsSceneObject);
Debug.Log(gameObject.scene.handle == SceneOriginHandle);
// Early exit if SceneMigrationSynchronization is disabled, there is no NetworkManager assigned,
// the NetworkManager is shutting down, the NetworkObject is not spawned, it is an in-scene placed
// NetworkObject, or the GameObject's current scene handle is the same as the SceneOriginHandle
if (!SceneMigrationSynchronization || !IsSpawned || NetworkManager == null || NetworkManager.ShutdownInProgress ||
!NetworkManager.NetworkConfig.EnableSceneManagement || IsSceneObject != false || gameObject.scene.handle == SceneOriginHandle)
{
return;
}
// Otherwise, this has to be a dynamically spawned NetworkObject that has been
// migrated to a new scene.
SceneChangedUpdate(gameObject.scene, true);
}
I put in an issue report after talking to someone on the Unity Networking Discord server.