fix: error when there are no network behaviors (#1303)

Use the lazy network behaviors cache everywhere, so this can never be null
This commit is contained in:
Paul Pacheco 2019-12-12 20:28:31 -06:00 committed by GitHub
parent ca4ff9b6b2
commit dbe064393a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}