From c9032985132039842ef0f612c4f7368aa001c2f4 Mon Sep 17 00:00:00 2001 From: mischa <16416509+miwarnec@users.noreply.github.com> Date: Sun, 17 Sep 2023 17:01:07 +0800 Subject: [PATCH] NetworkServer.Destroy: add warning if called on client without server/host to make this more obvious, instead of destroying something locally that doesn't persist on the server (#3604) --- Assets/Mirror/Core/NetworkServer.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index fceeafaa8..2577b054d 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -1492,6 +1492,14 @@ static void DestroyObject(NetworkIdentity identity, DestroyMode mode) { // Debug.Log($"DestroyObject instance:{identity.netId}"); + // NetworkServer.Destroy should only be called on server or host. + // on client, show a warning to explain what it does. + if (!active) + { + Debug.LogWarning("NetworkServer.Destroy() called without an active server. Servers can only destroy while active, clients can only ask the server to destroy (for example, with a [Command]), after which the server may decide to destroy the object and broadcast the change to all clients."); + return; + } + // only call OnRebuildObservers while active, // not while shutting down // (https://github.com/vis2k/Mirror/issues/2977)