Skip to content

Commit

Permalink
fix: error when there are no network behaviors (#1303)
Browse files Browse the repository at this point in the history
Use the lazy network behaviors cache everywhere, so this can never be null
  • Loading branch information
paulpach committed Dec 13, 2019
1 parent ca4ff9b commit dbe0643
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 + "].");
Expand Down Expand Up @@ -852,17 +846,16 @@ internal void OnStartLocalPlayer()
return;
previousLocalPlayer = this;

foreach (NetworkBehaviour comp in networkBehavioursCache)
foreach (NetworkBehaviour comp in NetworkBehaviours)
{
comp.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();
}
}
Expand Down

0 comments on commit dbe0643

Please sign in to comment.