Skip to content

NullReferenceException when host stops connection #2759

@Daniel4144

Description

@Daniel4144

Description

When the host disconnects and a certain object is not owned by the server, the following NullReferenceException is thrown:

NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.NetworkVariableBase.SetDirty (System.Boolean isDirty) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/NetworkVariable/NetworkVariableBase.cs:98)
Unity.Netcode.NetworkBehaviour.MarkVariablesDirty (System.Boolean dirty) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkBehaviour.cs:730)
Unity.Netcode.NetworkObject.MarkVariablesDirty (System.Boolean dirty) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkObject.cs:1127)
Unity.Netcode.NetworkSpawnManager.ChangeOwnership (Unity.Netcode.NetworkObject networkObject, System.UInt64 clientId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Spawning/NetworkSpawnManager.cs:266)
Unity.Netcode.NetworkSpawnManager.RemoveOwnership (Unity.Netcode.NetworkObject networkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Spawning/NetworkSpawnManager.cs:245)
Unity.Netcode.NetworkObject.RemoveOwnership () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkObject.cs:640)
Unity.Netcode.NetworkConnectionManager.OnClientDisconnectFromServer (System.UInt64 clientId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Connection/NetworkConnectionManager.cs:821)
Unity.Netcode.NetworkConnectionManager.DisconnectRemoteClient (System.UInt64 clientId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Connection/NetworkConnectionManager.cs:877)
Unity.Netcode.NetworkConnectionManager.Shutdown () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Connection/NetworkConnectionManager.cs:976)
Unity.Netcode.NetworkManager.ShutdownInternal () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkManager.cs:980)
Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkManager.cs:70)
Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkUpdateLoop.cs:185)
Unity.Netcode.NetworkUpdateLoop+NetworkPostLateUpdate+<>c.b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkUpdateLoop.cs:268)

I don't have a sample project I can share, but according to the error message no custom scripts are involved.
Reproduced in play mode and in windows build.

Environment

  • OS: Windows 10 220H2
  • Unity Version: 2023.3.12.f1
  • Netcode Version: 1.6.0 / 1.7.0

Metadata

Metadata

Assignees

Labels

good-first-issueContributions are welcome. Good first issue for newcomers or first time contributors.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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions