OK, I screwed something up. When the client leaves, no issues. When the host leaves, the client is fine (goes back to the Main menu and can join another game. But the host is borked and I get two errors:
NullReferenceException: Object reference not set to an instance of an object
NullReferenceException: Object reference not set to an instance of an object
Here’s the stack:
NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.NetworkList`1[T].MarkNetworkObjectDirty () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/NetworkVariable/Collections/NetworkList.cs:78)
Unity.Netcode.NetworkList`1[T].HandleAddListEvent (Unity.Netcode.NetworkListEvent`1[T] listEvent) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/NetworkVariable/Collections/NetworkList.cs:536)
Unity.Netcode.NetworkList`1[T].Remove (T item) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/NetworkVariable/Collections/NetworkList.cs:442)
Leaderboard.OnPlayerDespawned (TankPlayer tankPlayer) (at Assets/_Project/Scripts/UI/Leaderboard/Leaderboard.cs:78)
TankPlayer.OnNetworkDespawn () (at Assets/_Project/Scripts/Core/Player/TankPlayer.cs:45)
Unity.Netcode.NetworkBehaviour.InternalOnNetworkDespawn () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkBehaviour.cs:516)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.NetworkBehaviour:InternalOnNetworkDespawn() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkBehaviour.cs:520)
Unity.Netcode.NetworkObject:InvokeBehaviourNetworkDespawn() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkObject.cs:1083)
Unity.Netcode.NetworkSpawnManager:OnDespawnObject(NetworkObject, Boolean) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Spawning/NetworkSpawnManager.cs:849)
Unity.Netcode.NetworkSpawnManager:DespawnObject(NetworkObject, Boolean) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Spawning/NetworkSpawnManager.cs:667)
Unity.Netcode.NetworkConnectionManager:OnClientDisconnectFromServer(UInt64) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Connection/NetworkConnectionManager.cs:780)
Unity.Netcode.NetworkConnectionManager:DisconnectRemoteClient(UInt64) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Connection/NetworkConnectionManager.cs:877)
Unity.Netcode.NetworkConnectionManager:Shutdown() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Connection/NetworkConnectionManager.cs:976)
Unity.Netcode.NetworkManager:ShutdownInternal() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkManager.cs:980)
Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkManager.cs:70)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkUpdateLoop.cs:185)
Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkUpdateLoop.cs:268)
I’m having an issue tracking this one down. Any help would be awesome. I did some code comparisons and as far as I can tell, I have the same code, but I’m sure I missed something.
NOTE: If I remove the clearing of the leaderboard, it doesn’t throw the error. It seems the errors are thrown when it removes the hosts value from the leaderboard.
Thanks!
Julian