0
0
UnityDebug / FixBeginner · 4 min read

How to Fix Animation Not Playing in Unity Quickly

To fix animation not playing in Unity, ensure the Animator component is attached and properly configured with the correct Animator Controller. Also, verify your script triggers the animation using SetTrigger or Play methods and that the animation clips are correctly assigned.
🔍

Why This Happens

Animations in Unity often don't play because the Animator component is missing or not linked to an Animator Controller. Another common cause is that the script does not correctly trigger the animation state, or the animation clip is not assigned or enabled.

csharp
using UnityEngine;

public class Player : MonoBehaviour {
    void Start() {
        // Missing Animator component or controller
        // This will not play any animation
    }

    void Update() {
        if (Input.GetKeyDown(KeyCode.Space)) {
            // Trying to play animation without Animator
            Animator animator = GetComponent<Animator>();
            animator.Play("Jump");
        }
    }
}
Output
NullReferenceException: Object reference not set to an instance of an object UnityEngine.Animator.Play(String stateName) at Player.Update()
🔧

The Fix

Attach an Animator component to your GameObject and assign a valid Animator Controller with the animation states. In your script, get the Animator component once and use SetTrigger or Play to start the animation. Make sure the animation clip is included in the controller.

csharp
using UnityEngine;

public class Player : MonoBehaviour {
    private Animator animator;

    void Start() {
        animator = GetComponent<Animator>();
    }

    void Update() {
        if (Input.GetKeyDown(KeyCode.Space)) {
            animator.SetTrigger("JumpTrigger");
        }
    }
}
Output
When pressing Space, the 'Jump' animation plays smoothly on the character.
🛡️

Prevention

Always check that your GameObject has an Animator component with a properly configured Animator Controller. Use clear trigger or state names in your scripts and test animations in the Unity Editor before running. Keep animation clips organized and verify transitions in the Animator window.

⚠️

Related Errors

  • Animation clip not found: Ensure the clip is added to the Animator Controller.
  • Animator component disabled: Check if the Animator is enabled in the Inspector.
  • Wrong state name in script: Match the exact state or trigger name used in the Animator Controller.

Key Takeaways

Attach and configure the Animator component with a valid Animator Controller.
Trigger animations in scripts using SetTrigger or Play with correct names.
Verify animation clips are assigned and transitions set in the Animator window.
Test animations in the Editor to catch setup issues early.
Check for null references to avoid runtime errors when accessing Animator.