Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: NetworkBehaviors can be added to child gameobjects #371

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions Assets/Mirror/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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