mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
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:
parent
ca4ff9b6b2
commit
dbe064393a
@ -537,12 +537,6 @@ internal void NotifyAuthority()
|
|||||||
|
|
||||||
void OnStartAuthority()
|
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)
|
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -808,9 +802,9 @@ void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvokeType inv
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find the right component to invoke the function on
|
// 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))
|
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 + "].");
|
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;
|
return;
|
||||||
previousLocalPlayer = this;
|
previousLocalPlayer = this;
|
||||||
|
|
||||||
foreach (NetworkBehaviour comp in networkBehavioursCache)
|
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||||
{
|
{
|
||||||
comp.OnStartLocalPlayer();
|
comp.OnStartLocalPlayer();
|
||||||
}
|
}
|
||||||
@ -860,9 +854,8 @@ internal void OnStartLocalPlayer()
|
|||||||
|
|
||||||
internal void OnNetworkDestroy()
|
internal void OnNetworkDestroy()
|
||||||
{
|
{
|
||||||
for (int i = 0; networkBehavioursCache != null && i < networkBehavioursCache.Length; i++)
|
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||||
{
|
{
|
||||||
NetworkBehaviour comp = networkBehavioursCache[i];
|
|
||||||
comp.OnNetworkDestroy();
|
comp.OnNetworkDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user