Excuse me, guys.
I met a big problem using Netcode 1.0.0-pre.9
The problem is that error occurs when client disconnect with NetworkObject pooling.
The reason why this error occurs,
- 'Observers' in NetworkObject add when NetworkObject spawn or client connect, but doesn't remove when NetworkObject despawned.
- So if you pool NetworkObject, 'Observers' in pooled NetworkObject( == despawned NetworkObject) still has clientId (although client disconnect)
- When pooled NetworkObject respawn, they use unreliable clientIds. If that client disconnect, they make an error.
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary2[TKey,TValue].get_Item (TKey key) (at <695d1cc93cca45069c528c15c9fdd749>:0)
Unity.Netcode.MessagingSystem.SendPreSerializedMessage[TMessageType] (Unity.Netcode.FastBufferWriter& tmpSerializer, System.Int32 maxSize, TMessageType& message, Unity.Netcode.NetworkDelivery delivery, System.Collections.Generic.IReadOnlyList1[System.UInt64]& clientIds) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Messaging/MessagingSystem.cs:405)
- I think that the solution is adding networkObject.Observers.Clear() to NetworkSpawnManager.cs (line 528). It means that before NetworkObject respawn, clear obeservers.
I solved this problem temporarily like this (because only method to remove observers is NetworkHide function)
foreach (var id in NetworkManager.Singleton.ConnectedClientsIds)
{
if (id == NetworkManager.ServerClientId)
continue;
obj.GetComponent<NetworkObject>().NetworkHide(id);
}
obj.GetComponent().Despawn(false);
Please fix this problem as soon as possible!
Excuse me, guys.
I met a big problem using Netcode 1.0.0-pre.9
The problem is that error occurs when client disconnect with NetworkObject pooling.
The reason why this error occurs,
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary2[TKey,TValue].get_Item (TKey key) (at <695d1cc93cca45069c528c15c9fdd749>:0)
Unity.Netcode.MessagingSystem.SendPreSerializedMessage[TMessageType] (Unity.Netcode.FastBufferWriter& tmpSerializer, System.Int32 maxSize, TMessageType& message, Unity.Netcode.NetworkDelivery delivery, System.Collections.Generic.IReadOnlyList1[System.UInt64]& clientIds) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Messaging/MessagingSystem.cs:405)
I solved this problem temporarily like this (because only method to remove observers is NetworkHide function)
foreach (var id in NetworkManager.Singleton.ConnectedClientsIds)
{
if (id == NetworkManager.ServerClientId)
continue;
}
obj.GetComponent().Despawn(false);
Please fix this problem as soon as possible!