Tip for Null Reference on application quit

There was a big comment thread in the previous video about NetworkList throwing an error on application quit, which only appeared to happen for newer versions of NGO. I have a solution for you other than revering your NGO version.

Add these checks to your HandlePlayerDespawned call in Leaderboard (or anywhere else this may be a problem for you).

Class Leaderboard
{
    private void HandlePlayerDespawned(TankPlayer player)
    {
            if (!NetworkManager.Singleton.ConnectedClients.ContainsKey(player.OwnerClientId)
                || NetworkManager.Singleton.ShutdownInProgress)
            {
                return;
            }
    }
}

This “fix” resolves the error on the host side. Unity removes the host client id from the connected clients dictionary before “OnClientDisconnectedCallback” gets called. Unfortunately, NetworkLists seem to attempt a final behaviour update even if their client already disconnected in or after that frame. NetworkLists require client ids to do their work, so a missing id creates this error. Seems like an error that Unity should handle instead of putting this on us.

This solution fixes the error for the host/server, and I believe it has also fixed the client side. The issue seems harder to replicate client-side, but I was to log a success message from my fix once so far and I haven’t yet seen the error again.

Hope it helps.

1 Like

Privacy & Terms