Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Reverse animation error in Unity 5.1

Discussion in 'Animation' started by Agallardol, Jun 10, 2015.

  1. Agallardol

    Agallardol

    Joined:
    Jun 10, 2015
    Posts:
    4
    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!
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  3. Agallardol

    Agallardol

    Joined:
    Jun 10, 2015
    Posts:
    4
    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?
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    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.

    Code (CSharp):
    1.  
    2. void Animator::UpdateState(float deltaTime)
    3. {
    4.     deltaTime *= animatorState.speed;
    5. }
    6. void Animator::UpdateLayer(float deltaTime)
    7. {
    8.     UpdateState(deltaTime);
    9. }
    10.  
    11. void Animator::Update(float deltaTime)
    12. {
    13.     deltaTime *= animator.speed;
    14.     UpdateLayer(deltaTime);
    15. }