Skip to content

The problem is that error occurs when client disconnect with NetworkObject pooling. #2007

@kaygundraka

Description

@kaygundraka

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,

  1. 'Observers' in NetworkObject add when NetworkObject spawn or client connect, but doesn't remove when NetworkObject despawned.
  2. So if you pool NetworkObject, 'Observers' in pooled NetworkObject( == despawned NetworkObject) still has clientId (although client disconnect)
  3. 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)

  1. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions