Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[Unity3D]How to get reference to a specific Animation Clip in Animator

For the past 2 hours I have been searching everywhere and I can't find any resources to help me. The documentation is confusing (Especially for Animation) and every information I find is for a previous version of Unity that had a different animation system. Anyway, I have a GameObject with a Animator component attached. The Animator Controller has 4 animation states that it uses. I have a script attached to my GameObject and I can'd find out how to do the following: 1) Get the length any specific clip 2) Change the speed of any specific clip.

animator.speed = (some number) does not work because it changed the speed of ALL the clips. I want to change the speed of specific clips during runtime. Is there a way I can search the animation clip by name and change the clip speed? Or is there a way I can make a public AnimationClip, drag and drop the clip, and then edit the speed of the clip? And I want to change all of this during runtime, I know I can click on the Animation Clip and change the speed that way. Also, as I listed earlier, I need to get the length of the animation clip. I assume if I can change the speed of an animation clip, I can get the length of the clip because I'd have the reference to it. Any Help?

like image 496
user3738071 Avatar asked Nov 06 '25 13:11

user3738071


1 Answers

Use:

AnimationUtility.GetAnimationClips(GameObject)

By using this you will get all animationsClips in array from current gameObject. Then you will have everything you want.

See docs:

AnimationUtility.GetAnimationClips AnimationClip

like image 136
Kamil Spisak Avatar answered Nov 09 '25 03:11

Kamil Spisak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!