Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by darbotron · Jul 28, 2014 at 10:57 AM · animatoranimationclipanimation controllerstatesiterate

How do I iterate all animation clips used by an Animator?

Whilst MechAnim seems really great in most respects, it seems to unnecessarily hide an awful lot from us programmers...

Here's a concrete example:

I would like to iterate all the animation clips used by an Animator, in the Awake() function in order to do some special case setup based on the lengths (in seconds) of various animations that it uses.

This isn't possible with the current API - the best you can do is look at the current state and the next state (if there is one set).

This information only allows you to get at the animations that are currently being played - so if a state uses a blend tree and the weight is exactly 1.0 on just one of the animations in that blend tree, this will only allow you to get the information for that animation...

Then I thought "How silly of me! The animation clips are in the AnimationController. I obviously have to use that to access them."

Except this doesn't help, the runtimeAnimationController has more or less nothing in its interface. Certainly no way to iterate the layers, states. or motions it contains.

Then I found this thread: http://answers.unity3d.com/questions/418854/getting-a-list-of-mecanim-states-in-animator.html

this thread mentions using the UNDOCUMENTED UnityEditorInternal.AnimationController to access this information, but I need to use this code in the Awake() function which means that - whilst the game runs fine in the editor - I can't build it.

The only option I can see that's left to me (other than using the legacy animation system) is to make a custom serialised type to hold a description of the animation controller and use an associated custom property drawer to populate it from an animation controller.

This sounds like an insane amount of work to accomplish something which is - on the face of it - very simple: I just would like to iterate all animation clips used by an Animator.

Surely there's a way to use an Animator to iterate all the layers, states, and motions of its associated AnimationController at runtime!?!

Does anyone know how?

Cheers, Alex

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image darbotron · Jul 28, 2014 at 11:00 AM 0
Share

there is another obvious option:

Write a hideous hard-coded, entirely special case, non-reusable script that implicitly contains knowledge of the attached AnimationController's state machine so I don't need to iterate anything...

bleurgh.

2 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by AllFatherGray · Sep 28, 2015 at 06:28 AM

   Animator anim;//make this a field
    anim = GetComponent<Animator>();
     
     foreach(AnimationClip ac in anim.runtimeAnimatorController.animationClips)
     {
        // look at all the animation clips here!
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jo2015jojo · May 10, 2018 at 09:28 AM 0
Share

could you explain more on //look at all the animation clip here! part?

avatar image
1

Answer by lqvinh2 · Nov 21, 2018 at 08:48 AM

     AnimationClip[] arrclip = GetComponent<Animator>().runtimeAnimatorController.animationClips;
     foreach (AnimationClip clip in arrclip)
     {
         listNameClip.Add(clip.name);
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mirroring animation clip without mirroring root motion node? 0 Answers

How do I animate a 2D sprite? 1 Answer

The Quantum Animator? - Animator behaving differently when animation controller is open in editor 0 Answers

Frame Perfect Animations 0 Answers

Animator state stuck 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges