Skip to content

Commit

Permalink
fix: Scale Adjusters outside an avatar throw exceptions (#822)
Browse files Browse the repository at this point in the history
* fix: Scale Adjusters outside an avatar throw exceptions

* fix: improve scale adjuster performance
  • Loading branch information
bdunderscore committed Apr 15, 2024
1 parent 8d64c63 commit b25359a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ private void UpdateProxyParent(Transform proxyChild, Transform trueParent)
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);
}
Expand Down
13 changes: 12 additions & 1 deletion Runtime/ScaleAdjuster/ProxyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal static void RegisterAdjuster(ModularAvatarScaleAdjuster adjuster)
{
lock (_lock)
{
if (_adjusters.Contains(adjuster)) return;
_adjusters = _adjusters.Add(adjuster);
_dirty = true;
}
Expand Down Expand Up @@ -121,7 +122,17 @@ private static void BuildRenderers()
_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<SkinnedMeshRenderer>(true))
.ToList();

Expand Down

0 comments on commit b25359a

Please sign in to comment.