Skip to content

Missing Reference Exception when changing scene while player object is destroyed #3221

@Ed-Gilmour

Description

@Ed-Gilmour

When I load the players into a game and then destroy a client player object and have them leave while their player object is destroyed there is a missing reference exception that endlessly runs for the client the rest of time they have the game open.

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)

  1. Spawn player object on a client
  2. Despawn client player object
  3. While client player object is despawned load a different scene
  4. See error on client every frame

Error on client runs every frame for the rest of the time while the game is open. I tried going into the NetworkObject script and adding if(this == null) return; on line 3315 (UpdateForSceneChanges) and it stops making the error. This makes me believe that it might be getting cached somewhere like the scenemanager and its not getting cleared properly when the object is destroyed on shutdown.

I except the error to not appear and the rest of the game run normally.

  • OS: Windows 11
  • Unity Version: 6000.0.36f1
  • Netcode Version: 2.2.0

The attached game object to the NetworkObject when I was debugging it was null which is why I think it's not getting cleared properly and why the this == null is stopping the error every frame.

Metadata

Metadata

Labels

priority:mediumThis issue has medium priority and may take some time to be resolvedstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions