Skip to content

NetworkManager shutdown maintains references for the next scene #3218

@ArthurTelles

Description

@ArthurTelles

Description

After entering a scene and spawning NetworkObjects, I shutdown the NetworkManager and go back to the lobby. However, when transitioning to another scene and starting as a host again the NetworkManager starts showing errors from references from the previous scene.

Reproduce Steps

  1. Start the project in Scene A with NetworkManager not started

  2. In Scene B, start the host and spawn NetworkObjects that are nested

  3. Shut down the NetworkManager and return to Scene A

  4. Move back to Scene B, start as a host again, and encounter continuous error logs.

Actual Outcome

After exiting and entering the same scene the NetworkManager appears to maintain references from older NetworkObjects making the project throw uncountable errors.

Expected Outcome

The exact same code works fine on the NGO 1.12.2 but keeps throwing those errors on the versions 2+.

Environment

  • OS: macOS 15.2
  • Unity Version: 6000.0.34f1
  • Netcode Version: 2+

Additional Context

Here's is the error log I keep receiving after updating the version:

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 /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:869)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/BindingsHelpers.cs:61)
UnityEngine.Component.get_gameObject () (at <eac12af5e0034b02b1bfe348a7feb8c6>:0)
Unity.Netcode.NetworkObject.UpdateForSceneChanges () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs:3318)
Unity.Netcode.NetworkObject.UpdateNetworkObjectSceneChanges () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs:3287)
Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:404)
Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop+NetworkPostLateUpdate+<>c.<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:286)

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:highThis issue has high priority and we are focusing to resolve itstat: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