Animation Finder in Unity

The script I will be sharing with you today is called the Animation List script. If you are wondering what are the animations that exists inside a certain objects, this script will be helpful.

There are two scripts responsible for this.

AnimationFinder.cs

This script gets all the animations from the Animator component of the object. This is the script you apply to the GameObject.

using UnityEngine;

namespace MyInteractionKit
{
    public class AnimationFinder : MonoBehaviour
    {
        [HideInInspector]
        public AnimationClip[] animationClips; // This will hold the list of animation clips
        public Animator animator;

        void OnValidate()
        {
            // Get the Animator component attached to this GameObject
            animator = GetComponent<Animator>();

            if (animator != null)
            {
                // Get the RuntimeAnimatorController associated with the Animator
                RuntimeAnimatorController controller = animator.runtimeAnimatorController;

                if (controller != null)
                {
                    // Assign all animation clips to the public array
                    animationClips = controller.animationClips;
                }
            }
        }
    }
}

AnimationList.cs

This Editor script is responsible for listing the found animations in the Inspector. This should be put in a folder called Editor.

using UnityEngine;

namespace MyInteractionKit
{
    public class AnimationFinder : MonoBehaviour
    {
        [HideInInspector]
        public AnimationClip[] animationClips; // This will hold the list of animation clips
        public Animator animator;

        void OnValidate()
        {
            // Get the Animator component attached to this GameObject
            animator = GetComponent<Animator>();

            if (animator != null)
            {
                // Get the RuntimeAnimatorController associated with the Animator
                RuntimeAnimatorController controller = animator.runtimeAnimatorController;

                if (controller != null)
                {
                    // Assign all animation clips to the public array
                    animationClips = controller.animationClips;
                }
            }
        }
    }
}

Script Usage and Support:

This script is part of the upcoming MyInteractionKit, which will soon be available on the Unity Asset Store. Feel free to use this script as needed, whether it’s for personal projects, learning, or if you’re in a situation where purchasing the full kit isn’t feasible right now.

If you find this helpful and are in a position to do so, I invite you to support the full MyInteractionKit when it becomes available. Your support helps me continue to create and share more tools like this with the community.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top