Gameplay Polish - Issues

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

Hey Julian,
I think this error is associated with Netcode for GameObejcts 1.5 and newer, what version of netcode and unity are you on?

See my fix here:

Netcode for Gameobjects 1.5.2.

That worked! But now I have another error:

Unity.Services.Lobbies.LobbyServiceException: lobby not found —> Unity.Services.Lobbies.Http.HttpException`1[Unity.Services.Lobbies.Models.ErrorStatus]: (404) HTTP/1.1 404 Not Found

It seems that even though the host is dropping the connection, the “HostGameManager.HandleClientLeft” method is being triggered and then throws the error:

Unity.Services.Lobbies.LobbyServiceException: lobby not found ---> Unity.Services.Lobbies.Http.HttpException`1[Unity.Services.Lobbies.Models.ErrorStatus]: (404) HTTP/1.1 404 Not Found
  at Unity.Services.Lobbies.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.Lobbies.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) [0x0007b] in ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Http/ResponseHandler.cs:114 
  at Unity.Services.Lobbies.Apis.Lobby.LobbyApiClient.RemovePlayerAsync (Unity.Services.Lobbies.Lobby.RemovePlayerRequest request, Unity.Services.Lobbies.Configuration operationConfiguration) [0x0019c] in ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Apis/LobbyApi.cs:612 
  at Unity.Services.Lobbies.Internal.WrappedLobbyService.TryCatchRequest[TRequest] (System.String api, System.Func`3[T1,T2,TResult] func, TRequest request) [0x0006b] in ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/SDK/WrappedLobbyService.cs:350 
   --- End of inner exception stack trace ---
  at Unity.Services.Lobbies.Internal.WrappedLobbyService.ResolveErrorWrapping (Unity.Services.Lobbies.LobbyExceptionReason reason, System.Exception exception) [0x000bf] in ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/SDK/WrappedLobbyService.cs:459 
  at Unity.Services.Lobbies.Internal.WrappedLobbyService.TryCatchRequest[TRequest] (System.String api, System.Func`3[T1,T2,TResult] func, TRequest request) [0x0010b] in ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/SDK/WrappedLobbyService.cs:355 
  at Unity.Services.Lobbies.Internal.WrappedLobbyService.RemovePlayerAsync (System.String lobbyId, System.String playerId) [0x000a3] in ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/SDK/WrappedLobbyService.cs:261 
  at HostGameManager.HandleClientLeft (System.String authId) [0x00039] in /Users/julianboardman/Documents/GitHub/Gamedev.tv Multiplayer/Assets/_Project/Scripts/Networking/Host/HostGameManager.cs:144 
UnityEngine.Debug:LogError (object)
HostGameManager/<HandleClientLeft>d__16:MoveNext () (at Assets/_Project/Scripts/Networking/Host/HostGameManager.cs:148)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetException (System.Exception)
Unity.Services.Lobbies.Internal.WrappedLobbyService/<RemovePlayerAsync>d__19:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/SDK/WrappedLobbyService.cs:261)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Response>:SetException (System.Exception)
Unity.Services.Lobbies.Internal.WrappedLobbyService/<TryCatchRequest>d__25`1<Unity.Services.Lobbies.Lobby.RemovePlayerRequest>:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/SDK/WrappedLobbyService.cs:386)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Response>:SetException (System.Exception)
Unity.Services.Lobbies.Apis.Lobby.LobbyApiClient/<RemovePlayerAsync>d__20:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Apis/LobbyApi.cs:613)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<MakeRequestAsync>d__1:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Http/HttpClient.cs:41)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<CreateWebRequestAsync>d__3:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Http/HttpClient.cs:56)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<CreateHttpClientResponse>d__4:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Http/HttpClient.cs:84)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<>c__DisplayClass4_0/<<CreateHttpClientResponse>b__0>d:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Http/HttpClient.cs:81)
System.Threading.Tasks.TaskCompletionSource`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.UnityWebRequestHelpers/<>c__DisplayClass0_0:<GetAwaiter>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.lobby@1.1.0/Runtime/Http/UnityWebRequestHelpers.cs:34)
UnityEngine.AsyncOperation:InvokeCompletionEvent () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/AsyncOperation.cs:21)

Worst case, I can just ignore that specific error. Maybe it’s because I’m using Lobby 1.1.0?

Thanks so much for your help!

Julian

This error is being thrown on the client when the host leaves?

Oddly enough, it’s being thrown by the host when the host disconnects. When I use the editor as the client, zero errors are thrown. It’s not a deal breaker. The game can continue to set up a new lobby and add players back. I’m just more curious than anything else.

Thanks!

Julian

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms