Skip to content

Commit

Permalink
feat: NetworkBehaviors can be added to child gameobjects (#371)
Browse files Browse the repository at this point in the history
* feat: NI can also find components in children

* NB no longer requires a NI,  it can be in the parent

* Find disabled ones too
  • Loading branch information
paulpach committed Sep 30, 2020
1 parent 6d04228 commit 266dc8d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Assets/Mirror/Runtime/NetworkBehaviour.cs
Expand Up @@ -20,7 +20,6 @@ public enum SyncMode { Observers, Owner }
/// <para>Some of the built-in components of the networking system are derived from NetworkBehaviour, including NetworkTransport, NetworkAnimator and NetworkProximityChecker.</para>
/// </remarks>
[AddComponentMenu("")]
[RequireComponent(typeof(NetworkIdentity))]
[HelpURL("https://mirror-networking.com/docs/Guides/NetworkBehaviour.html")]
public abstract class NetworkBehaviour : MonoBehaviour
{
Expand Down Expand Up @@ -147,7 +146,7 @@ public NetworkIdentity NetIdentity
// instead of calling unity's MonoBehaviour == operator
if (((object)netIdentityCache) == null)
{
netIdentityCache = GetComponent<NetworkIdentity>();
netIdentityCache = GetComponentInParent<NetworkIdentity>();
// do this 2nd check inside first if so that we are not checking == twice on unity Object
if (netIdentityCache == null)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/NetworkIdentity.cs
Expand Up @@ -205,7 +205,7 @@ public NetworkBehaviour[] NetworkBehaviours
if (networkBehavioursCache != null)
return networkBehavioursCache;

NetworkBehaviour[] components = GetComponents<NetworkBehaviour>();
NetworkBehaviour[] components = GetComponentsInChildren<NetworkBehaviour>(true);

if (components.Length > 64)
throw new InvalidOperationException("Only 64 NetworkBehaviour per gameobject allowed");
Expand Down

0 comments on commit 266dc8d

Please sign in to comment.