From ab7d48756f92222eaadc167646c1234a2a875d4b Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Wed, 30 Sep 2020 14:51:30 -0500 Subject: [PATCH 1/3] feat: NI can also find components in children --- Assets/Mirror/Runtime/NetworkBehaviour.cs | 2 +- Assets/Mirror/Runtime/NetworkIdentity.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index c75564869bf..47f6d2466d7 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -147,7 +147,7 @@ public NetworkIdentity NetIdentity // instead of calling unity's MonoBehaviour == operator if (((object)netIdentityCache) == null) { - netIdentityCache = GetComponent(); + netIdentityCache = GetComponentInParent(); // do this 2nd check inside first if so that we are not checking == twice on unity Object if (netIdentityCache == null) { diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index 45ed1714bd5..ab6b7fb02df 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -205,7 +205,7 @@ public NetworkBehaviour[] NetworkBehaviours if (networkBehavioursCache != null) return networkBehavioursCache; - NetworkBehaviour[] components = GetComponents(); + NetworkBehaviour[] components = GetComponentsInChildren(); if (components.Length > 64) throw new InvalidOperationException("Only 64 NetworkBehaviour per gameobject allowed"); From d2ca9ac958a9e8cabd51f630c5ddb1b9e660f8ec Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Wed, 30 Sep 2020 14:55:05 -0500 Subject: [PATCH 2/3] NB no longer requires a NI, it can be in the parent --- Assets/Mirror/Runtime/NetworkBehaviour.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index 47f6d2466d7..6d5924be4c9 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -20,7 +20,6 @@ public enum SyncMode { Observers, Owner } /// Some of the built-in components of the networking system are derived from NetworkBehaviour, including NetworkTransport, NetworkAnimator and NetworkProximityChecker. /// [AddComponentMenu("")] - [RequireComponent(typeof(NetworkIdentity))] [HelpURL("https://mirror-networking.com/docs/Guides/NetworkBehaviour.html")] public abstract class NetworkBehaviour : MonoBehaviour { From 02417534f54f8f4a4d5479af43d1adb80dda0c6e Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Wed, 30 Sep 2020 15:20:23 -0500 Subject: [PATCH 3/3] Find disabled ones too --- Assets/Mirror/Runtime/NetworkIdentity.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index ab6b7fb02df..24729449057 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -205,7 +205,7 @@ public NetworkBehaviour[] NetworkBehaviours if (networkBehavioursCache != null) return networkBehavioursCache; - NetworkBehaviour[] components = GetComponentsInChildren(); + NetworkBehaviour[] components = GetComponentsInChildren(true); if (components.Length > 64) throw new InvalidOperationException("Only 64 NetworkBehaviour per gameobject allowed");