How to play an animation forwards and backwards with animation controller?

I’m trying to play a simple animation alternating forwards and backwards, in the simplest possible way, and I’m stumped at how the Unity animation system works (as can be seen from my other threads on this topic):

Animations do not have a loop time.
Take 001 plays to end and waits for trigger, no issue.
Take 001 0 is multiplied by Direction, and just snaps back to the original state, never animating.

I’ve even attached a test project if someone wants to take a look.

3456720–274038–animation-controller-test.zip (1.68 MB)

Instead of this - change Take 001 0 speed to -1.

That is what Direction does. If you look in my screenshot you can see that it has a value of -1.

Ouch, I just found this thread:

@Mecanim-Dev is my issue related? Seems like it shouldn’t be though, because I can’t think of a simpler animation case…

Not to be adverse - but I downloaded your pack and recreated the state machine with your animations and instead of having the animation condition/parameter (?), just changed the speed to -1 and it worked perfectly, in the simplest way possible.

That’s not being adverse, that’s explaining your point and that’s great!

Now, mathematically, there should not be any difference between Speed * Direction and Speed = -1, right?

Yet, as you said, Speed - 1 works, but if you multiply it with the Direction parameter, it does not. Bug?

Also, I managed to get it working exactly once. And then the Animator Controller state machine displays stopped updating, and I’m now back at the default snap to 0 behavior again. I can’t even see my “No Motion” state animate when I press play on my project. Another bug? I’m using Unity 2017.4.f1.

1 Like

well there is a difference between Speed = 1 * Direction = -1 and Speed = -1

When the speed of a state is negative the whole clip is flipped, meaning that the end of the clip is now the beginning of the clip. That the behaviour that you want

there is a reason why it never animate in this case, you’re animation clip take 001 doesn’t have loop time ON, so when the time hit the beginning or end of the clip it won’t loop back.
So with a speed = 1, the clip start at 0, and with a direction of -1 the time goes backward but since the clip time doesn’t loop its stuck at the beginning.

The right way to do a ping pong clip is with a first state with speed = 1 and the second one with a speed = -1.

2 Likes

Thank you for clarifying. Very finnicky for someone who isn’t a developer.

Still, the bug where there is a delay on the second state still seems to persist even with this method…

(Also, the Animation Controller not showing any animation that I mentioned is due to the way you select it, I discovered. You have to have the game object highlighted for the animation controller to update, despite only one game object ever using that controller. Again, very finnicky.)

the delay is caused by the exit time condition, an exit time condition can only be fulfilled when the previous evaluation time is < ExitTime and the current evaluation is >= Exit Time.

So if you press Animate and the current time is by example 2.25, the system will trigger the next transition when the time goes beyond 3.0.

1 Like

No, I’ve tried both with and without Exit Time, it does not matter. There is a delay the every time you start the animation regardless, except for the first time, which is instant.

See this thread:

And this bug report:

https://fogbugz.unity3d.com/default.asp?1018899_873l6ld4lkfuk9rl

(Note that the above two links are without any transitions, but the project attached to this thread is with transitions, yet the result is the same, even if you adjust to speed -1.)

1 Like