Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Animation in reverse -1 mode not working

Discussion in 'Animation' started by bisewski, Nov 16, 2023.

  1. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    Hi!
    Code (CSharp):
    1.  public void pause(float frame)
    2. {
    3. //working fine, When Events call here the clip start to back as spected.
    4. //currentAnimator.SetFloat("speed", -1);          
    5. //return;
    6.  
    7. currentAnimator.SetFloat("speed", 0);      
    8.      float time = ((frame+1) / frameLenght);
    9.      frameStoped = frame;      
    10.      currentAnimator.Play("Base Layer.disassemble", 0, time);
    11.      print("stoped");
    12. }
    13. public void PlayNext()
    14. {  
    15.      currentAnimator.SetFloat("speed", 1);
    16. }
    17. public void PlayBack()
    18. {
    19.      float time = ((frameStoped - 5) / frameLenght);
    20.      currentAnimator.Play("Base Layer.disassemble", 0, time);
    21.      currentAnimator.SetFloat("speed", -1);  
    22. }
    What I am missing in this code? I already used this code but now just not working.
    Everything is fine. I can advance in my animation and Events calls pause(). Fine.

    If I play next I start animation from where I had stopped.

    But to back is the problem. The time in PlayBack is correct, I tested.
    But for some reason when I call PlayBack() I always enter in Events that call pause. So I cant back. Still in the same position.

    The idea is jump the Event that will call pause(). This is because I am using "frameStoped - 5". Means less 5 frames. If I stoped in 180 where I have the Event, I try to start in reverse from 175...

    This code worked but now i dont know whats happens. Is another version from Unity but I think that inst the case.

    Thank you for ideas...
     
  2. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    the corious is that the animation jump to the correct time but always call the Event...

    If I put manuality the value for example like currentAnimator.Play("Base Layer.disassemble", 0, 0.08f); and the current time paused is 0.09f, the anim jump to 0.08f. Is like 0.09f in frame 180 and 0.08f is frame 175...And The Event is in 179.
     
  3. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    ish..I had setted Application.targetFrameRate = 30;

    So when I disable this line works fine. Probably so will not work in mobiles...
     
  4. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    iep. not working in mobile.

    Probably something with these lines:
    Code (CSharp):
    1. float timeOfAnimation = currentAnimator.runtimeAnimatorController.animationClips[2].length;    
    2. frameLenght = timeOfAnimation * 60;
    I dont know how get the total frames...
     
  5. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    What I am not understanding is that in my tests I can jump to the target frame or position by normalized time but always is calling the Event. I am try to jump this Event but even I jumping to a far frame, the Events is called!!!
     
  6. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    I used spheres in each frames with differents colors.
    So when I click in back, I am jump to the right place. So I used a green sphere in the same frame at the Events, in the next frame a blue and in the prev a red.

    And everything is working, I click in back and the red sphere is showed. The problem is that it isnt inverting the direction of the animation.

    If I call direct it like commented in my script, the animation is reverted. But in back isnt working because I jump tp the desired frame but I keep the positive direction, so Event is trigurred again...
     
  7. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    If I remove the pause in Events, just using a return inside the pause() when I click to reverse, it revert!!!

    Really...I am tired...
     
  8. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    If I use idle.disassembleModel in currentAnimator.Play("idle.disassembleModel", 0, time); the animation is backing.
    But i am getting this error:

    Animator.GotoState: State could not be found
    UnityEngine.Animator:play (string,int,single)
     
  9. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    If i use currentAnimator.Play("Base Layer.disassembleModel", 0, 0); I didnt receive the error but again the script inst jumping the Event! Is like the error is helping me...Maybe a delay?
     
  10. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    print(currentAnimator.GetCurrentAnimatorStateInfo(0).IsName("idle.disassembleModel")) ; This return false.
    print(currentAnimator.GetCurrentAnimatorStateInfo(0).IsName("disassembleModel")) ; It return True.

    Only in when I use idle.disassembleModel that is False, the animation play back ad forward....Not jumping the Event. So we need to click twice. One to reverte and hit the Event that will call pause. After it clicking again will play correctly...
     
  11. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    274
    Ok...Definilly the issue is about the Events is called even if e jump direct to a distance frame. Or there are a setting to block it or I am in throuble...