diff --git a/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs b/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs index 6e8da683..a995c900 100644 --- a/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs +++ b/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs @@ -112,13 +112,15 @@ namespace nadena.dev.modular_avatar.core trueParent = trueParent.parent; } + // Clean up any additional parentage we might not want if (proxyChild.parent != null) { + Transform parent = proxyChild.parent; + // Reparent to root proxyChild.SetParent(null, false); // Destroy old hierarchy - Transform parent = proxyChild.parent; while (parent.parent != null) parent = parent.parent; DestroyImmediate(parent.gameObject); } diff --git a/Runtime/ScaleAdjuster/ProxyManager.cs b/Runtime/ScaleAdjuster/ProxyManager.cs index 3ee39a86..49d6560d 100644 --- a/Runtime/ScaleAdjuster/ProxyManager.cs +++ b/Runtime/ScaleAdjuster/ProxyManager.cs @@ -31,6 +31,7 @@ namespace nadena.dev.modular_avatar.core { lock (_lock) { + if (_adjusters.Contains(adjuster)) return; _adjusters = _adjusters.Add(adjuster); _dirty = true; } @@ -121,7 +122,17 @@ namespace nadena.dev.modular_avatar.core _dirty = false; } - var avatarRoots = _capturedBones.Keys.Select(RuntimeUtil.FindAvatarTransformInParents).ToImmutableHashSet(); + var avatarRoots = _capturedBones.Keys.Select(bone => + { + var root = RuntimeUtil.FindAvatarTransformInParents(bone); + if (root == null) + { + root = bone; + while (root.parent != null) root = root.parent; + } + + return root; + }).ToImmutableHashSet(); var potentialRenderers = avatarRoots.SelectMany(r => r.GetComponentsInChildren(true)) .ToList();