fix: NetworkServer.Destroy now warns instead of throwing for null objects again

This commit is contained in:
mischa 2024-03-06 11:20:56 +08:00 committed by MrGadget
parent c15d465874
commit b90f6f30ab

View File

@ -1559,7 +1559,7 @@ public static void UnSpawn(GameObject obj)
{
// Debug.Log($"DestroyObject instance:{identity.netId}");
// NetworkServer.Destroy should only be called on server or host.
// NetworkServer.Unspawn should only be called on server or host.
// on client, show a warning to explain what it does.
if (!active)
{
@ -1640,6 +1640,20 @@ public static void UnSpawn(GameObject obj)
// NetworkServer.Destroy().
public static void Destroy(GameObject obj)
{
// 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;
}
if (obj == null)
{
Debug.Log("NetworkServer.Destroy(): object is null");
return;
}
// first, we unspawn it on clients and server
UnSpawn(obj);