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)

This commit is contained in:
mischa 2023-09-17 17:01:07 +08:00 committed by GitHub
parent c49d188e8b
commit c903298513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)