Reverse animation error in Unity 5.1

My code use the AnimatorController’s property speed = -1 for reverse an animation as far.
Today, i updated Unity to version 5.1 and my code doesn’t work because in this version the speed is clamped to 0 when i try change it to -1.

Changelog say this:

Animation: Animator.speed can only be negative when the recorder is enabled. Now when the recorder is offline we do clamp the speed to 0 to avoid negative speed.

How can i run an animation backwards in Unity 5.1 if the speed can’t be negative?

Thanks!

You should use this new feature from 5.1
Runtime Animator State Properties (speed, mirror, cycleOffset) for 5.1 - Unity Engine - Unity Discussions.

This will allow you to control each state speed individually if needed. There is a few issue remainning in the final 5.1 release but they are already fixed in 5.1p1 which should be available really soon

4 Likes

Hi @Mecanim-Dev ,
With my team we have tried your solution, and it works!

Now, we have a new problem.

Our software is for medical purpose, so we need accuracy in our complex algorithms. This way, we are using the Mecanim system for handle an animation and simulate the human’s movements. Order to do this we change continuosly (many times, one time by frame) the animation speed and with the old Unity’s version, that is to say, calling “animator.speed” the algorithm works perfectly and accurately, but with the new Unity’s version, that is to say, callin “animator.Set(“SpeedParameter”, value)”, the algorithm works with accuracy’s errors and delayed. So we think that “animator.speed = value” is faster than “animator.Set(“SpeedParameter”, value)” changing the real speed value.

Do you know any solution for this problem?
If animator.Set(“SpeedParameter”, value) is more slow than animator.speed, Is there any chance that Unity optimize this feature or anything?

I would like to see why you think it not as accurate as before. Do you have any project to show this? Because under the hood both method use the same technic. Each time the animator is ticked we read either animator.speed or your’s speed parameter and we multiply the delta time by this speed value, the only different is that animator.speed is multiply with the global delta time and speed parameter is multiply with the state delta time.

void Animator::UpdateState(float deltaTime)
{
    deltaTime *= animatorState.speed;
}
void Animator::UpdateLayer(float deltaTime)
{
    UpdateState(deltaTime);
}

void Animator::Update(float deltaTime)
{
    deltaTime *= animator.speed;
    UpdateLayer(deltaTime);
}