From ede2c6c2c2d8f238dfbb86fe759f95bb07ddebfb Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 27 Aug 2020 14:27:49 +0200 Subject: [PATCH] NetworkServer.SpawnObject shows a warning when called with a server-only NetworkIdentity --- Assets/Mirror/Runtime/NetworkServer.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 50ceebeb8..110963358 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -73,7 +73,7 @@ public static class NetworkServer public static float disconnectInactiveTimeout = 60f; /// - /// cache the Send(connectionIds) list to avoid allocating each time + /// cache the Send(connectionIds) list to avoid allocating each time /// static readonly List connectionIdsCache = new List(); @@ -217,7 +217,7 @@ public static bool RemoveConnection(int connectionId) } /// - /// called by LocalClient to add itself. dont call directly. + /// called by LocalClient to add itself. dont call directly. /// /// internal static void SetLocalConnection(ULocalConnectionToClient conn) @@ -975,7 +975,7 @@ public static void SetClientNotReady(NetworkConnection conn) } /// - /// default ready handler. + /// default ready handler. /// /// /// @@ -1060,6 +1060,14 @@ internal static void SpawnObject(GameObject obj, NetworkConnection ownerConnecti return; } + // spawning a server-only NetworkIdentity won't do anything, but + // might confuse someone. let's show a warning. + if (identity.serverOnly) + { + logger.LogWarning("SpawnObject for " + obj + " is server-only. Calling NetworkServer.Spawn wouldn't do anything."); + return; + } + if (identity.SpawnedFromInstantiate) { // Using Instantiate on SceneObject is not allowed, so stop spawning here