# How to play an animation backwards in Unity?

I know this question has been asked before but it all involves using the Animation(?) component, so that is no longer any good in Unity 5.3.1f1, I explain a bit more later.

I'm trying to simply get an animation to play backwards. On the object that I want to have an animation play backwards on, I have an animator.

private Animator anim;
...
anim = GetComponent<Animator>();


If I do:

animator.speed = -1.0f;


It tells me Animator.speed can only be negative when Animator recorder is enabled. Animator.recorderMode != AnimatorRecorderMode.Offline

So I try putting on an Animation component on the game object, and making the clip the animation.

Every time I do anything with the Animation component in script, it tells me the component must be marked as Legacy. That is no good, because when I tried making it Legacy it caused multiple problems including not being recognized by the Animator. Also GetRef errors. The entire Animation component seems like it's treated as legacy now or is just broken.

So I decided well maybe I could just try to get the animation to play backwards in the animator and having the animator record it, and then using that backwards recorded animation in the actual game. I cannot figure out how to this, even if I click record in the Animation view anim.recorderMode != AnimatorRecorderMode.Record. I don't know what to do. All I want to do is play the same animation backwards without having to copy and paste an animation in the Project and moving all of the keys around so that they are reversed. Please help. Unity's animation system seems so convoluted in script.

This can all be done in the Controller.

All you need to do is create another state. In my example I created a walk and walk backwards:

The walk state is just the walking animation, it takes in a float parameter called "Speed" and transitions from idol when speed is greater than zero.

The walk backwards state, which is simply the walk animation played with speed -1 (see below) can be transitioned to from the walking state if the speed is less than zero. ( an unconventional state machine because you can't go from idol to backwards or from backwards to forwards, but this was contrived for the example.)

• You are most welcome XD Feb 11 '16 at 2:42
• is asking to play the animation backwards, not to play a different animation Oct 16 '19 at 3:42

I've been working with Unity 5.3 and another way I found is to create a new float parameter for the animator controller. Call it direction. Enable it as a multiplier parameter for the Speed (with Speed equaling 1) in the state you wish to play in reverse.

Then in the scripting set 'direction' = -1f and the animation plays in reverse.

Animtor anim = GetComponent<Animator>();
anim.SetFloat('direction', -1);