From unity-skills
Animation avancee dans Unity : Animator, IK, Root Motion, Timeline, Playables API, Animation Rigging, blend trees. Triggers: /anim, /animation, 'Animator avance', 'IK', 'Root Motion', 'Timeline', 'Playables API', 'Animation Rigging', 'blend tree', 'state machine animation', 'animation events'.
How this skill is triggered — by the user, by Claude, or both
Slash command
/unity-skills:unity-animationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Guider l'implementation d'animations avancees dans Unity. Couvre l'integration code-Animator, IK, Root Motion, Animation Rigging, Timeline, Playables API et blend trees avances.
Guider l'implementation d'animations avancees dans Unity. Couvre l'integration code-Animator, IK, Root Motion, Animation Rigging, Timeline, Playables API et blend trees avances.
Cette skill va au-dela de la simple configuration d'Animator Controller : elle fournit les patterns de code production-ready pour piloter les animations depuis le code, synchroniser la logique gameplay avec les keyframes, et exploiter les systemes avances (IK, Playables API, Timeline).
com.unity.animation.rigging) pour l'IKcom.unity.timeline) pour les cutscenesQuel systeme d'animation ?
|
+-- Animation simple (porte, plateforme, UI) ?
| --> Animation component simple (legacy) ou Animator avec 1-2 states
|
+-- Personnage joueur ou ennemi avec etats (idle, run, attack) ?
| --> Animator Controller + State Machine + code integration
|
+-- Animation cinematique / cutscene ?
| --> Timeline (PlayableDirector + tracks)
|
+-- Melange dynamique d'animations a runtime ?
| --> Playables API (mixer custom)
|
+-- IK (personnage regarde/attrape un objet) ?
| --> Animation Rigging package (Rig Builder + constraints)
|
+-- Besoin de performance extreme (milliers d'entites) ?
--> DOTS Animation (voir /unity-dots)
[RequireComponent(typeof(Animator))]
public class CharacterAnimator : MonoBehaviour
{
private Animator animator;
// TOUJOURS cacher les hash (evite les string lookups chaque frame)
private static readonly int SpeedHash = Animator.StringToHash("Speed");
private static readonly int IsGroundedHash = Animator.StringToHash("IsGrounded");
private static readonly int JumpTrigger = Animator.StringToHash("Jump");
private static readonly int AttackTrigger = Animator.StringToHash("Attack");
private void Awake() => animator = GetComponent<Animator>();
public void SetSpeed(float speed) => animator.SetFloat(SpeedHash, speed);
public void SetGrounded(bool grounded) => animator.SetBool(IsGroundedHash, grounded);
public void TriggerJump() => animator.SetTrigger(JumpTrigger);
public void TriggerAttack() => animator.SetTrigger(AttackTrigger);
}
// Appele depuis un clip d'animation a un keyframe precis
public void OnFootstep()
{
audioService.PlaySFX(footstepClip);
}
public void OnAttackHit()
{
// Activer hitbox au bon moment de l'animation
hitbox.SetActive(true);
}
public void OnAttackEnd()
{
hitbox.SetActive(false);
}
public class AttackState : StateMachineBehaviour
{
public override void OnStateEnter(
Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.GetComponent<CombatSystem>().OnAttackStart();
}
public override void OnStateExit(
Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.GetComponent<CombatSystem>().OnAttackEnd();
}
}
// Controle dynamique du poids d'un layer (ex: upper body attack)
private static readonly int UpperBodyLayer = 1;
public void EnableUpperBodyOverride(float weight)
{
animator.SetLayerWeight(UpperBodyLayer, weight);
}
Dans l'Animator Controller :
MoveX (float), MoveY (float)private static readonly int MoveXHash = Animator.StringToHash("MoveX");
private static readonly int MoveYHash = Animator.StringToHash("MoveY");
public void SetMovement(Vector2 input)
{
// Smooth damp pour eviter les changements brusques
animator.SetFloat(MoveXHash, input.x, 0.1f, Time.deltaTime);
animator.SetFloat(MoveYHash, input.y, 0.1f, Time.deltaTime);
}
TOUJOURS :
Animator.StringToHash (pas de strings dans Update)SetFloat avec damping pour des transitions fluides dans les blend treesPlayableGraph dans OnDestroy() pour eviter les fuites memoireJAMAIS :
GetComponent<Animator>() dans Update -- cacher la reference dans Awaketransition duration = 0 sauf pour les state machines purement logiques (cause des snaps visuels)transform.position manuellement quand Root Motion est actifPlay() ou CrossFade() sans raison -- preferer les transitions de l'Animator ControllerPREFERER :
OnAnimatorIK() pour les nouveaux projets/unity-code-gen -- generer des StateMachineBehaviour et boilerplate Animator/proto -- prototyper rapidement avec des animations simples/unity-dots -- DOTS animation pour des milliers d'entites animees/2d -- animation 2D avec Sprite Library et Sprite Swap| Probleme | Solution |
|---|---|
| Animation ne joue pas | Verifier que le state est atteignable (transitions connectees), que le parametre est set correctement |
| Personnage glisse/flotte | Root Motion mal configure -- verifier "Apply Root Motion" sur l'Animator et les curves du clip |
| Blend Tree saccade | Verifier que les clips ont la meme cadence de pas (foot cycle). Ajuster le threshold |
| IK ne fonctionne pas | Verifier que le layer a "IK Pass" active dans l'Animator Controller |
| Animation Event pas appele | La methode doit etre publique, sur le meme GameObject que l'Animator, avec la bonne signature |
| Transition bloquee | Verifier les conditions de transition, desactiver "Has Exit Time" si transition immediate souhaitee |
| Layer override ne marche pas | Verifier l'Avatar Mask du layer, et que le weight > 0 |
| PlayableGraph leak | Toujours appeler graph.Destroy() dans OnDestroy() |
npx claudepluginhub juliankerignard/unity-skillsUnity 6 animation system guide. Use when working with Animator Controllers, animation state machines, blend trees, animation clips, Avatar system, humanoid rigs, root motion, animation events, Timeline, or Cinemachine. Based on Unity 6.3 LTS documentation.
Provides GDScript and C# examples for Godot 4.3+ animations using AnimationPlayer for playback, AnimationTree for blending and state machines, sprite animation, and code-driven effects.
Wires Godot 4.5 AnimationTree state machines and blend spaces from existing clips. Activates when the user has idle/walk/run/attack clips and needs smooth transitions, hit reactions, or interrupts.