Skip to content

Commit

Permalink
fix: animator recreation needs to happen in bottom-up order
Browse files Browse the repository at this point in the history
Closes: #163
  • Loading branch information
bdunderscore committed Feb 12, 2024
1 parent 09858e9 commit e888ec1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Editor/ApplyOnPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ private static void RecreateAnimators(Transform avatar)
// It's important to actually recreate animators here - if we try, for example, calling Rebind,
// it can still start moving around stale bone references.
var tmpObject = new GameObject();
foreach (var animator in avatar.GetComponentsInChildren<Animator>(true))

// Note that we need to recreate animators from the bottom up. This ensures that certain hacks where
// animators animate other animators work properly (e.g. https://github.com/hfcRed/Among-Us-Follower/tree/main)
foreach (var animator in avatar.GetComponentsInChildren<Animator>(true).Reverse())
{
// We need to store animator configuration somewhere while we recreate it.
// Since we can't add two animators to the same object, we'll just stash it on a
Expand All @@ -129,7 +132,7 @@ private static void RecreateAnimators(Transform avatar)

var tmpAnimator = tmpObject.AddComponent<Animator>();
bool enabled = animator.enabled;

EditorUtility.CopySerialized(animator, tmpAnimator);
UnityObject.DestroyImmediate(animator);
var newAnimator = obj.AddComponent<Animator>();
Expand All @@ -139,6 +142,7 @@ private static void RecreateAnimators(Transform avatar)

UnityObject.DestroyImmediate(tmpAnimator);
}

UnityObject.DestroyImmediate(tmpObject);
}

Expand Down

0 comments on commit e888ec1

Please sign in to comment.