CodeBlanks Logo Icon CodeBlanks

The Animator component

Learn how the Animator component works with an Animator Controller.

Working with an Animator Controller

The Animator component manages animations on a GameObject. The Animator Controller determines which animations play and under which conditions they change. Assigning a controller to the Animator component's Controller field establishes this connection.

Animator animator;

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

Verifying the Controller Connection

The runtimeAnimatorController property provides the Animator Controller assigned to an Animator component. You can check this property to determine whether a controller has been assigned.

if (animator.runtimeAnimatorController != null)
{
    Debug.Log("Controller connected");
}

Practice Check the Controller Connection

Access the Animator component and check whether an Animator Controller has been assigned. If a controller exists, print Controller found to the console.

Starter code

Player.cs
using UnityEngine;

public class ControllerCheck : MonoBehaviour
{
    private Animator animator;

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

Sample solution

Player.cs
using UnityEngine;

public class ControllerCheck : MonoBehaviour
{
    private Animator animator;

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

        if (animator.runtimeAnimatorController != null)
        {
            Debug.Log("Controller bulundu");
        }
    }
}

Expected output

Controller bulundu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the main purpose of an Animator Controller?

  • Managing animations and transitions between them Correct answer
  • Calculating scene lighting
  • Managing physics collisions
  • Compressing audio files

Explanation: An Animator Controller manages animation states and transitions.

2 Check the Controller Property

Question
if (animator.____ != null)
{
    Debug.Log("Controller hazır");
}
Answer
if (animator.runtimeAnimatorController != null)
{
    Debug.Log("Controller hazır");
}

Explanation: runtimeAnimatorController is used to check the controller asset assigned to an Animator component.

3 Match the Animator Structure

Term Meaning
Animator Controller Asset used to manage animations
Animator Component Component that runs animations
runtimeAnimatorController Access to assigned controller asset
State Machine System organizing animation states

All lessons in Intermediate