The new Animator component in Unity can post a few problems when dealing with animation speed. I will present here three methods in which you can control it.
By default animation speed is set to 1 and that means it will play with the speed the artist intended it. However you can change that factor. You can set it to 2 in order to play twice as fast or to 0.5 to play twice as slow. You can either set it to a negative number in order to have it play backwards.
1. Set speed in animation state
Select an animation state in the animator window and up in the Inspector you should see this
You can set the speed in the speed box as explained above
2. Use the Animator component in code
You can obtain the animator component in code by calling GetComponentInChildren<Animator>() method. Then you can change the speed by changing the value of Animator.speed property. You can do so dynamically if you need to change speed on the fly from code or want to pause speed in order to freeze the animation.
Unfortunately using this method has a side effect in case you have more than one animation for this particular object as it governs the animation speeds for all playing animations for this object. Because of this issues, this should be used with care and is suitable for objects with one animation playing at a time.
3. Use a blending tree
Right click an animation state and select “Create New Blend Tree in State” like in this image
Double click the state to enter it. In the lower left corner click the “+” sign on parameters and add a Float parameter which will control the animation speed
You can see that the parameter is automatically selected as the blending tree parameter
Click the “+” button in inspector and add click the “Add Motion Field” option and add the animation in question. Do this again and add the same animation.
Uncheck the Automate Thresholds option
Set at which threshold the animation should start and for which speed in the box to the right
There we go, the three animation speed changing ways I’ve learned so far in the new Unity’s Animator component, hope you find them useful.
Please share any other ways you know of accomplishing this task.