- Home /
Problem adding individual clip speed
I've been trying to figure this out for hours now and i can't get it right :C
I have the player object which has an animator which has the controller. In this object i have about 3 different animations and i want to change the speed of one of them.
i know i can do something like: animation["swing"].speed = speed; but that gives me an error saying that there is no animation attached to player object.
i have one reference to the animator: anim = GetComponent();
and if i do anim.speed = speed; that does increase the speed but to every single clip. So how can i change the animation speed of one single clip?
Thanks in advance!
You might wanna refer to this thread that provides a work around.
$$anonymous$$ecanim - Change animation speed of specific animation or layers
And also refer:
Dynamic $$anonymous$$ecanim animation speed/time
Sometimes a Search does the trick! :-P
animation["swing"].speed = speed
is a legacy call, for Animation component, not Animator, which is $$anonymous$$ecanim.
I believe you can modify the speed of the whole layer but not an individual animation. To do this you need to alter it within the state machine.
To do it per animation simply detect the animation being played and conditionally set the speed of the layer.
Alternatively, set up a new state in the Animator which is the same animation, but faster, perhaps with a Blend Tree for a variable range.
@meat5000 you just summed up the two links that I provided. O$$anonymous$$G! :-0
I did search and for like 2 hours :C but all that came up was the animation.speed all over the place haha. I found most of the stuff too complex so i went along with working around of "Set playback of the entire Animator using [Animator.speed][1]. Note that this overrides the speeds of all states in your controller. Probably not your best bet.". Changed the entire animator speed before playing the animation i wanted and setted it back to normal in an animation event at the end of the last frame. Not sure if that is an "okay" way to do it so i will look into detecting the animation being played and set up the layer's speed. Thank you guys :)
Answer by KarlKarl2000 · Feb 12, 2017 at 04:16 PM
Sorry to necro a thread. But in case others find this thread like me.
Meat's answer is good. But it also speeds up all the animations on that particular layer.
Unity came up with a solution (finally) after a couple years.
sharing is caring
Good find. I havent so well kept up to date on Additions to the system. You can have the Accepted answer.
Answer by meat5000 · Jun 20, 2014 at 07:19 PM
Yes, use
if( animator.GetCurrentAnimatorStateInfo(Layer).IsName("yourAnimation"))
{
animator.speed = animSpeed;
}
Where Layer is the animation layer as int and animSpeed is a float to determine animation speed, where 1 is normal.
This way you can set individual speeds for individual animations.
I've never tried it though, I just whipped it up today to answer the same question from about 5 different people :D
So, you saw it here first :P maybe :D
Late reply... 4 years late... Im trying to figure out how to Slow down PARTS of the animation... I like to use "add event" inside my Animation so I have control over exactly when the time should slow down. but how do I give that command inside a "void" (<--using void so I can see the event inside the animation when I add a flag on the timeline)
$$anonymous$$y advice here is to construct and submit a nice full question and we'll have a look :)
Your answer
Follow this Question
Related Questions
mecanim animation runs at random speed on iOS 0 Answers
Use Humanoid Animations with aditional bones 2 Answers
[Unity 4.3] Skinned legacy animations do not work 1 Answer
Mecanim - changing animation clip speed, through script? 4 Answers
Stop Animation State in Animator from Speeding Up after Playing it a Second Time? 0 Answers