com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
NetworkConfig cached Hash not cleared when switching server
So I noticed that if I try to disconnect from a server (for example a lobby server that doesn't manage scenes) and try to connect to another server (for example game server that manage scenes), it doesn't work, even though I setup the config on client to be exactly the same than the server I try to connect to.
I realized that the problem is because m_ConfigHash inside NetworkConfig.cs is already set and is never recalculated, even after a Shutdown(). And there are no way to clear the cache.
This is the concerned code: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/develop/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs#L237-L255
Suggested solutions :
A) Add a function to clear the cache inside NetworkConfig.cs
public void ClearConfigHash()
{
m_ConfigHash = null;
}
B) Don't cache on the client, or clear the cache whenever you disconnect on client Caching makes sense on a server, because it could accept hundreds of connections... But on the client it doesn't make as much sense, because the client connects less often, and also more likely to disconnect and connect to a different type of server. Also whenever you disconnect with Shutdown(), it could reset the m_ConfigHash var. Since I believe that the cache is intended more for the server that stays online and would accept multiple connections before shutdown.
More info in discord: https://discord.com/channels/449263083769036810/563033158480691211/1014565598505738270
Summarized here: Many values used in the hash wouldn't typically change between servers in an application. Some, like SceneManagement could change between e.g. Lobby and Game servers. We should:
- Implement a ResetCash or InvalidateCachedHash or similar on NetworkConfig
- Pass
falsetoGetConfiginSendConnectionRequest- caching this client-side doesn't make sense, and this is the easiest way to cache for server but not client.
Backlog MTT-4605
@Marc477 It turns out that we just need to make a client regenerate the NetworkConfig hash value for each unique ConnectionRequestMessage since that is only sent by clients. This fix should be in the next update. 👍
This fix will be in the next update!