Closed
Description
Description
If you register multiple connectional approval callbacks on NetworkManager.Singleton.ConnectionApprovalCallback
, then you will get an exception because NetworkManager.HandleApproval
will be invoked twice for the same client. An exception is thrown when trying to add the client multiple times to m_ConnectedClients
.
ArgumentException: An item with the same key has already been added. Key: 0
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <cc07565d1e884982b04875f1b674afb1>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <cc07565d1e884982b04875f1b674afb1>:0)
Unity.Netcode.NetworkManager.HandleApproval (System.UInt64 ownerClientId, System.Boolean createPlayerObject, System.Nullable`1[T] playerPrefabHash, System.Boolean approved, System.Nullable`1[T] position, System.Nullable`1[T] rotation) (at /Users/james.lao/Code/com.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:1828)
Reproduce Steps
- Register more than one connection approval callback that all approve the connection.
- Start as host.
Actual Outcome
An exception is thrown when trying to .Add()
the client to the m_ConnectedClients
dictionary.
Expected Outcome
Either disallow multiple connection approval callbacks or handle it correctly.
Screenshots
n/a
Environment
- OS: macOS Monterey Big Sur
- Unity Version: 2021.15f1
- Netcode Version: latest from develop branch
- Netcode Commit: b8b6dfc
Additional Context
n/a