Skip to content

Commit

Permalink
fix: access NI on disabled objects (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymdun committed Oct 5, 2020
1 parent 64fd6ed commit 0ab4c60
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Assets/Mirror/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ public NetworkIdentity NetIdentity
// instead of calling unity's MonoBehaviour == operator
if (((object)netIdentityCache) == null)
{
netIdentityCache = GetComponentInParent<NetworkIdentity>();
// GetComponentInParent doesn't works on disabled gameobjecs
// and GetComponentsInParent(false)[0] isn't allocation free, so
// we just drop child support in this specific case
if (gameObject.activeSelf)
netIdentityCache = GetComponentInParent<NetworkIdentity>();
else
netIdentityCache = GetComponent<NetworkIdentity>();

// do this 2nd check inside first if so that we are not checking == twice on unity Object
if (netIdentityCache == null)
{
Expand Down

0 comments on commit 0ab4c60

Please sign in to comment.