void OptimizeHierarchy(Animator animator) { foreach (var animators in ObjectUtil.GetAll <Animator>(this)) { var root = animator.gameObject; var transforms = ObjectUtil.GetAll <Component>(root) .Where(comp => !(comp is Transform)) .Select(comp => comp.name) .Distinct() .ToArray(); AnimatorUtility.OptimizeTransformHierarchy(root, transforms); } }