Skip to content
Unity Animation logo

Unity Animation

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'.

SKILL.md

Full skill instructions

Unity Animation

Ce que fait cette 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.

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).

Prerequis

  • Animator Controller configure avec les states et transitions de base
  • Animation clips importes (Humanoid ou Generic rig selon le cas)
  • (Optionnel) Package Animation Rigging (com.unity.animation.rigging) pour l'IK
  • (Optionnel) Package Timeline (com.unity.timeline) pour les cutscenes

Demarrage rapide

  1. Choisir le systeme d'animation adapte au besoin (voir arbre de decision)
  2. Configurer l'Animator Controller (states, transitions, parametres)
  3. Integrer avec le code (hash caches, parametres, events)
  4. Affiner avec IK, blending avance, layers

Arbre de decision

Quel 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)

Guide etape par etape

Step 1 : Setup Animator + code integration

[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);
}

Step 2 : Animation Events

// 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);
}

Step 3 : StateMachineBehaviour (logique attachee aux states)

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();
    }
}

Step 4 : Animator Layers (animations partielles)

// 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);
}
  • Layer 0 : Base (locomotion complete)
  • Layer 1 : Upper Body Override (attaque, interaction) avec Avatar Mask
  • Layer 2 : Additive (breathing, hit reactions)

Step 5 : Blend Trees pour la locomotion

Dans l'Animator Controller :

  • Creer un Blend Tree 2D Freeform Directional
  • Parametres : MoveX (float), MoveY (float)
  • Motions : idle (0,0), walk forward (0,0.5), run forward (0,1), strafe left (-1,0), strafe right (1,0)
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);
}

Regles strictes

TOUJOURS :

  • Cacher les hash avec Animator.StringToHash (pas de strings dans Update)
  • Utiliser les Animation Events pour synchroniser logique et animation (pas de timers manuels)
  • Utiliser des Animator Layers pour les animations partielles (upper body attack + lower body run)
  • Utiliser SetFloat avec damping pour des transitions fluides dans les blend trees
  • Detruire les PlayableGraph dans OnDestroy() pour eviter les fuites memoire

JAMAIS :

  • GetComponent<Animator>() dans Update -- cacher la reference dans Awake
  • transition duration = 0 sauf pour les state machines purement logiques (cause des snaps visuels)
  • Modifier transform.position manuellement quand Root Motion est actif
  • Utiliser Play() ou CrossFade() sans raison -- preferer les transitions de l'Animator Controller

PREFERER :

  • Les Blend Trees 2D Freeform pour le mouvement directionnel
  • Les Sub-State Machines pour organiser les Animator Controllers complexes
  • Les Override Controllers pour reutiliser une state machine avec des clips differents
  • Animation Rigging plutot que OnAnimatorIK() pour les nouveaux projets

Skills connexes

  • /​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

Troubleshooting

ProblemeSolution
Animation ne joue pasVerifier que le state est atteignable (transitions connectees), que le parametre est set correctement
Personnage glisse/​flotteRoot Motion mal configure -- verifier "Apply Root Motion" sur l'Animator et les curves du clip
Blend Tree saccadeVerifier que les clips ont la meme cadence de pas (foot cycle). Ajuster le threshold
IK ne fonctionne pasVerifier que le layer a "IK Pass" active dans l'Animator Controller
Animation Event pas appeleLa methode doit etre publique, sur le meme GameObject que l'Animator, avec la bonne signature
Transition bloqueeVerifier les conditions de transition, desactiver "Has Exit Time" si transition immediate souhaitee
Layer override ne marche pasVerifier l'Avatar Mask du layer, et que le weight > 0
PlayableGraph leakToujours appeler graph.Destroy() dans OnDestroy()

More skills from JulianKerignard

Unity UI Toolkit logo
JulianKerignard/Unity-Skills

Unity UI Toolkit

Creation d'interfaces utilisateur avec UI Toolkit (UXML, USS, C# bindings). Genere des ecrans complets avec structure UXML, styling USS et presenter C#. Triggers: /uitk, /ui, 'UI Toolkit', 'UXML', 'USS', 'UIDocument', 'data binding UI', 'runtime UI', 'menu principal', 'HUD', 'interface utilisateu...

7 0
View
Unity Refactor logo
JulianKerignard/Unity-Skills

Unity Refactor

Refactoring incremental et securise de code C# Unity. Detecte les code smells, propose un plan priorise par risque, et execute les changements un par un avec verification de compilation. Triggers: /unity-refactor, 'refactor', 'code smell', 'clean code', 'dette technique', 'refactoring unity'. Pro...

7 0
View
Unity Editor Tools logo
JulianKerignard/Unity-Skills

Unity Editor Tools

Cree des outils custom pour l'editeur Unity : inspectors personnalises, fenetres d'outils, drawers, menu items, wizards et asset processors. Triggers: /unity-editor-tools, /editor, 'custom inspector', 'editor window', 'property drawer', 'menu item', 'editor tool', 'outil editeur'. Produit des scr...

7 0
View
Unity Perf Audit logo
JulianKerignard/Unity-Skills

Unity Perf Audit

Audit statique de performance pour projets Unity. Triggers: /perf, /perf-audit, 'audit performance', 'optimiser performance', 'anti-pattern performance', 'frame rate', 'profiler', 'budget fps'. Analyse le code C# du projet pour detecter les anti-patterns de performance (CPU, GPU, memoire). Produi...

7 0
View
Unity Build & CI/CD Configurator logo
JulianKerignard/Unity-Skills

Unity Build & CI/CD Configurator

Configure le pipeline de build Unity, CI/CD, et deployment. Triggers: /build-config, /ci, /deploy, 'configurer build', 'github actions unity', 'gitlab ci unity', 'gitignore unity', 'build automation'. Scanne le projet, genere les scripts de build C#, les workflows CI/CD, et les fichiers Git optim...

7 0
View
Unity DOTS logo
JulianKerignard/Unity-Skills

Unity DOTS

Data-Oriented Technology Stack (ECS, Job System, Burst). Authoring, baking, systems, queries, jobs paralleles. Triggers: /dots, /ecs, 'DOTS', 'ECS', 'ISystem', 'SystemAPI', 'IJobEntity', 'Burst', 'NativeArray', 'Entity', 'IComponentData', 'data oriented'.

7 0
View
Unity Save System logo
JulianKerignard/Unity-Skills

Unity Save System

Implementer un systeme de sauvegarde et persistence : /unity-save, /save, sauvegarde, save system, persistence, sauvegarder, charger une partie, save game, PlayerPrefs, serialisation, JSON save, cloud save, slot de sauvegarde

7 0
View
Unity Addressables logo
JulianKerignard/Unity-Skills

Unity Addressables

Asset loading et content management avec Addressables. Organisation des groupes, chargement async, memory management, remote content. Triggers: /addressables, /assets, 'Addressables', 'AssetReference', 'chargement async', 'remote content', 'DLC', 'asset bundles', 'Resources.Load migration', 'load...

7 0
View
Unity Code Gen logo
JulianKerignard/Unity-Skills

Unity Code Gen

Generation de code C# Unity production-ready a partir de specifications fonctionnelles. Analyse la codebase existante, choisit le bon pattern architectural, genere le code et les tests. Triggers: /unity-code-gen, 'generer script Unity', 'creer composant', 'nouveau MonoBehaviour', 'creer Scriptabl...

7 0
View
Unity 2D logo
JulianKerignard/Unity-Skills

Unity 2D

Guide complet pour le developpement 2D dans Unity 6+ : Tilemap, Sprite, 2D platformer, top-down 2D, 2D physics, Light2D, Sprite Atlas, pixel art, 2D game, jeu 2D, tile, Rule Tile. Commandes : /unity-2d, /2d

7 0
View
Unity Audio logo
JulianKerignard/Unity-Skills

Unity Audio

Systeme audio complet Unity 6+ : SFX, musique, ambiance, spatialisation 3D, AudioMixer, pooling, Audio Random Container, Scriptable Audio Pipeline. Triggers: /unity-audio, /audio, audio, son, musique, AudioMixer, AudioSource, spatial audio, 3D sound, sound design, SFX

7 0
View
Unity Shader Generator logo
JulianKerignard/Unity-Skills

Unity Shader Generator

Genere des shaders Unity (HLSL/ShaderLab) pour effets visuels. Triggers: /shader, /shader-gen, 'creer un shader', 'effet visuel shader', 'dissolve', 'outline', 'toon shading', 'hologram', 'water shader'. Detecte automatiquement le render pipeline (URP/HDRP/Built-in) et produit un fichier .shader ...

7 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View