1
\$\begingroup\$

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.

\$\endgroup\$
-1
\$\begingroup\$

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:

enter image description here

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.)

enter image description here

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You are most welcome XD \$\endgroup\$ – CostelloNicho Feb 11 '16 at 2:42
  • \$\begingroup\$ is asking to play the animation backwards, not to play a different animation \$\endgroup\$ – Delcasda Oct 16 '19 at 3:42
3
\$\begingroup\$

I've been working with Unity 5.3 and another way I found to do it was to create a new float parameter for the animator controller (call it 'direction') and then enable it as a multiplier parameter for the Speed (with Speed = 1) in the state you wish to play in reverse.

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

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

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.