diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be022e..e55c7bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Changed +- [#468] Performance improvements ### Removed diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index 86ffbc8..54cbe8e 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -29,8 +29,7 @@ static RuntimeUtil() // Shadow the VRC-provided methods to avoid deprecation warnings internal static T GetOrAddComponent(this GameObject obj) where T : Component { - var component = obj.GetComponent(); - if (component == null) component = obj.AddComponent(); + if (!obj.TryGetComponent(out var component)) component = obj.AddComponent(); return component; } @@ -95,10 +94,10 @@ public static string AvatarRootPath(GameObject child) public static bool IsAvatarRoot(Transform target) { #if NDMF_VRCSDK3_AVATARS - return target.GetComponent(); + return target.TryGetComponent(out _); #else - var an = target.GetComponent(); - if (!an) return false; + if (!target.TryGetComponent(out _)) return false; + var parent = target.transform.parent; return !(parent && parent.GetComponentInParent()); #endif