NetworkBehaviour: Improved comments

This commit is contained in:
MrGadget 2024-01-26 02:02:53 -05:00
parent 454e453767
commit 7a2cae3cfd

View File

@ -312,13 +312,13 @@ protected virtual void OnValidate()
// GetComponentInParent(includeInactive) is needed because Prefabs are not
// considered active, so this check requires to scan inactive.
#if UNITY_EDITOR
#if UNITY_2021_3_OR_NEWER // 2021 has GetComponentInParents(active)
#if UNITY_2021_3_OR_NEWER // 2021 has GetComponentInParent(bool includeInactive = false)
if (GetComponent<NetworkIdentity>() == null &&
GetComponentInParent<NetworkIdentity>(true) == null)
{
Debug.LogError($"{GetType()} on {name} requires a NetworkIdentity. Please add a NetworkIdentity component to {name} or it's parents.", this);
}
#elif UNITY_2020_3_OR_NEWER // 2020 only has GetComponentsInParents(active), we can use this too
#elif UNITY_2020_3_OR_NEWER // 2020 only has GetComponentsInParent(bool includeInactive = false), we can use this too
NetworkIdentity[] parentsIds = GetComponentsInParent<NetworkIdentity>(true);
int parentIdsCount = parentsIds != null ? parentsIds.Length : 0;
if (GetComponent<NetworkIdentity>() == null && parentIdsCount == 0)