From 100847cc3158c1b8d3fcd01cc0ba47be66860755 Mon Sep 17 00:00:00 2001 From: mischa <16416509+vis2k@users.noreply.github.com> Date: Fri, 30 Dec 2022 18:02:34 +0100 Subject: [PATCH] fix: #3308 scene change NetworkClient.owned null entry. NetworkIdentity.OnDestroy now removes from owned. (#3325) --- Assets/Mirror/Core/NetworkIdentity.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Assets/Mirror/Core/NetworkIdentity.cs b/Assets/Mirror/Core/NetworkIdentity.cs index e66977daa..858f3af62 100644 --- a/Assets/Mirror/Core/NetworkIdentity.cs +++ b/Assets/Mirror/Core/NetworkIdentity.cs @@ -629,6 +629,20 @@ void OnDestroy() if (NetworkClient.localPlayer == this) NetworkClient.localPlayer = null; } + + if (isClient) + { + // ServerChangeScene doesn't send destroy messages. + // some identities may persist in DDOL. + // some are destroyed by scene change. + // if an identity is still in .owned, remove it. + // fixes: https://github.com/MirrorNetworking/Mirror/issues/3308 + if (NetworkClient.connection != null && + NetworkClient.connection.owned.Contains(this)) + { + NetworkClient.connection.owned.Remove(this); + } + } } internal void OnStartServer()