Skip to content

Commit

Permalink
fix(NetworkClient): Remove OnHostClientObjectDestroy (#3964)
Browse files Browse the repository at this point in the history
NetworkServer::UnSpawnInternal already does everything we need to do, and since the identity is removed from spawned before the ObjectDestroyMessage is sent the lookup never succeeds and the spawned.Remove was already done.
- NetworkServer.Destroy calls UnSpawnInternal which does all the cleanup.
  • Loading branch information
MrGadget1024 authored Dec 30, 2024
1 parent 651d544 commit 6994cb8
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions Assets/Mirror/Core/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ internal static void RegisterMessageHandlers(bool hostMode)
// 'message id not found' errors.
if (hostMode)
{
RegisterHandler<ObjectDestroyMessage>(OnHostClientObjectDestroy);
// host mode doesn't need destroy messages (see NetworkServer::UnSpawnInternal)
RegisterHandler<ObjectDestroyMessage>(_ => { });
RegisterHandler<ObjectHideMessage>(OnHostClientObjectHide);
RegisterHandler<NetworkPongMessage>(_ => { }, false);
RegisterHandler<SpawnMessage>(OnHostClientSpawn);
Expand Down Expand Up @@ -1320,17 +1321,6 @@ internal static void OnObjectSpawnFinished(ObjectSpawnFinishedMessage _)
}

// host mode callbacks /////////////////////////////////////////////////
static void OnHostClientObjectDestroy(ObjectDestroyMessage message)
{
//Debug.Log($"NetworkClient.OnLocalObjectObjDestroy netId:{message.netId}");

// remove from owned (if any)
if (spawned.TryGetValue(message.netId, out NetworkIdentity identity))
connection.owned.Remove(identity);

spawned.Remove(message.netId);
}

static void OnHostClientObjectHide(ObjectHideMessage message)
{
//Debug.Log($"ClientScene::OnLocalObjectObjHide netId:{message.netId}");
Expand Down

0 comments on commit 6994cb8

Please sign in to comment.