NetworkServer.SpawnObject shows a warning when called with a server-only NetworkIdentity

This commit is contained in:
vis2k 2020-08-27 14:27:49 +02:00
parent f6dbf8c19e
commit ede2c6c2c2

View File

@ -73,7 +73,7 @@ public static class NetworkServer
public static float disconnectInactiveTimeout = 60f; public static float disconnectInactiveTimeout = 60f;
/// <summary> /// <summary>
/// cache the Send(connectionIds) list to avoid allocating each time /// cache the Send(connectionIds) list to avoid allocating each time
/// </summary> /// </summary>
static readonly List<int> connectionIdsCache = new List<int>(); static readonly List<int> connectionIdsCache = new List<int>();
@ -217,7 +217,7 @@ public static bool RemoveConnection(int connectionId)
} }
/// <summary> /// <summary>
/// called by LocalClient to add itself. dont call directly. /// called by LocalClient to add itself. dont call directly.
/// </summary> /// </summary>
/// <param name="conn"></param> /// <param name="conn"></param>
internal static void SetLocalConnection(ULocalConnectionToClient conn) internal static void SetLocalConnection(ULocalConnectionToClient conn)
@ -975,7 +975,7 @@ public static void SetClientNotReady(NetworkConnection conn)
} }
/// <summary> /// <summary>
/// default ready handler. /// default ready handler.
/// </summary> /// </summary>
/// <param name="conn"></param> /// <param name="conn"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
@ -1060,6 +1060,14 @@ internal static void SpawnObject(GameObject obj, NetworkConnection ownerConnecti
return; 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) if (identity.SpawnedFromInstantiate)
{ {
// Using Instantiate on SceneObject is not allowed, so stop spawning here // Using Instantiate on SceneObject is not allowed, so stop spawning here