Skip to content

Commit

Permalink
Merge pull request #1366 from anatawa12/fix-same-animator-on-avatar
Browse files Browse the repository at this point in the history
fix: Errors if exactly same AnimatorController is specified for playable layers
  • Loading branch information
anatawa12 authored Dec 8, 2024
2 parents 722f8f8 + 15b3ee9 commit 5df9b79
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog].

### Fixed
- Errors with models with UV at very edge `#1363`
- Errors if exactly same AnimatorController is specified for multiple playable layers `#1366`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog].

### Fixed
- Errors with models with UV at very edge `#1363`
- Errors if exactly same AnimatorController is specified for multiple playable layers `#1366`

### Security

Expand Down
13 changes: 6 additions & 7 deletions Editor/Processors/InitializeAnimatorOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ protected override void Execute(BuildContext context, TraceAndOptimizeState stat
switch (component)
{
case Animator animator:
animator.runtimeAnimatorController = ProcessController(animator.runtimeAnimatorController, component.gameObject);
ProcessController(animator.runtimeAnimatorController, component.gameObject);
break;
#if AAO_VRCSDK3_AVATARS
case VRCAvatarDescriptor avatarDescriptor:
foreach (ref var layer in avatarDescriptor.baseAnimationLayers.AsSpan())
layer.animatorController = ProcessController(layer.animatorController, component.gameObject);
ProcessController(layer.animatorController, component.gameObject);
foreach (ref var layer in avatarDescriptor.specialAnimationLayers.AsSpan())
layer.animatorController = ProcessController(layer.animatorController, component.gameObject);
ProcessController(layer.animatorController, component.gameObject);
#endif
break;
// do not run animator optimizer with unknown components
Expand All @@ -62,14 +62,14 @@ protected override void Execute(BuildContext context, TraceAndOptimizeState stat
}
}

AnimatorController? ProcessController(RuntimeAnimatorController? runtimeController,
void ProcessController(RuntimeAnimatorController? runtimeController,
GameObject rootGameObject)
{
if (runtimeController == null) return null;
if (runtimeController == null) return;
var cloned = (AnimatorController)runtimeController;
var wrapper = new AOAnimatorController(cloned, rootGameObject);
animatorState.Add(wrapper);
clonedToController.Add(cloned, wrapper);
if (!clonedToController.TryAdd(cloned, wrapper)) return;

#if AAO_VRCSDK3_AVATARS
foreach (var behaviour in ACUtils.StateMachineBehaviours(cloned))
Expand All @@ -83,7 +83,6 @@ protected override void Execute(BuildContext context, TraceAndOptimizeState stat
}
}
#endif
return cloned;
}

#if AAO_VRCSDK3_AVATARS
Expand Down

0 comments on commit 5df9b79

Please sign in to comment.