From dbe064393a6573bcb213b628ec53b547d04891cc Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Thu, 12 Dec 2019 20:28:31 -0600 Subject: [PATCH] fix: error when there are no network behaviors (#1303) Use the lazy network behaviors cache everywhere, so this can never be null --- Assets/Mirror/Runtime/NetworkIdentity.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index 36fc34a3b..e250af5ff 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -537,12 +537,6 @@ internal void NotifyAuthority() void OnStartAuthority() { - if (networkBehavioursCache == null) - { - Debug.LogError("Network object " + name + " not initialized properly. Do you have more than one NetworkIdentity in the same object? Did you forget to spawn this object with NetworkServer?", this); - return; - } - foreach (NetworkBehaviour comp in NetworkBehaviours) { try @@ -808,9 +802,9 @@ void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvokeType inv } // find the right component to invoke the function on - if (0 <= componentIndex && componentIndex < networkBehavioursCache.Length) + if (0 <= componentIndex && componentIndex < NetworkBehaviours.Length) { - NetworkBehaviour invokeComponent = networkBehavioursCache[componentIndex]; + NetworkBehaviour invokeComponent = NetworkBehaviours[componentIndex]; if (!invokeComponent.InvokeHandlerDelegate(functionHash, invokeType, reader)) { Debug.LogError("Found no receiver for incoming " + invokeType + " [" + functionHash + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); @@ -852,7 +846,7 @@ internal void OnStartLocalPlayer() return; previousLocalPlayer = this; - foreach (NetworkBehaviour comp in networkBehavioursCache) + foreach (NetworkBehaviour comp in NetworkBehaviours) { comp.OnStartLocalPlayer(); } @@ -860,9 +854,8 @@ internal void OnStartLocalPlayer() internal void OnNetworkDestroy() { - for (int i = 0; networkBehavioursCache != null && i < networkBehavioursCache.Length; i++) + foreach (NetworkBehaviour comp in NetworkBehaviours) { - NetworkBehaviour comp = networkBehavioursCache[i]; comp.OnNetworkDestroy(); } }