Skip to content

Commit

Permalink
fix: animator recreation needs to happen in bottom-up order (#165)
Browse files Browse the repository at this point in the history
Closes: #163
  • Loading branch information
bdunderscore authored Feb 12, 2024
1 parent 09858e9 commit 0513680
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Avatar names with leading/trailing whitespace broke builds (#161)
- Ave3mu's "Run Preprocess Avatar Hook" option was force-enabled even when apply on play was disabled (#160)
- Animator cloning broke "Among Us" follower due to sus processing order (#165)

### Changed
- Changed the hook processing logic to closer match VRCSDK (improves compatibility with VRCF and other external hooks)
Expand Down
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 0513680

Please sign in to comment.