- Home /
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?
Unity recently made exposed the individual clip speed. You can make a clip's speed dependent on a animation variable, so just create a float "speed", link it to the speed, and change the speed from your movement script, for example.
There is no simple way to reference an animation state. You have to first get an array of all states, then loop through then, and if the one you are searching for is reached, return that one.
Your answer
Follow this Question
Related Questions
How to interrupt and replay an animation? 0 Answers
How to reset animator controller ? 4 Answers
How to play an Animation only once from my MachineState Animator? 2 Answers
Animator Controller 2D RPG Best Practices 0 Answers
Some parts of animation not playing 0 Answers