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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

animation.Rewind() not working?

Discussion in 'Scripting' started by tomjoad, Apr 27, 2007.

  1. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    hey all! anyone know why 'animation.Rewind();' doesn't rewind an animation? I want to reset it to it's start point. Is this a bug or am I not using the command correctly?

    It plays forward just fine.

    tx!

    --Roy
     
  2. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    It's possible that you may not being using it correctly. Post a few lines from your script and we can take a look.
     
  3. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    thanks -

    I run the animation using this:

    Code (csharp):
    1. animation.Play("Default", PlayMode.StopAll);

    and I am trying to rewind (i.e. go back to the first frame of the animation using this:

    Code (csharp):
    1. animation.Rewind();
    It's not throwing any errors - it's just not returning the object (that the animation is attached to) back to it's starting position.

    --Roy
     
  4. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Hmmm... is the frame that it remains on (when it should be rewound) telling at all?

    I.e. do you have anything that is locking it that frame (ClampForever maybe?)
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Rewind does not start an animation automatically. Since you stopped it before, it will still be stopped after Rewind as well, thus after the animation is stopped it wont modify any values on the transforms or whatever you are animating.
     
  6. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    I'm not sure I understand. I wasn't expecting Rewind() to start my animation, I expected it to return the animation to it's first frame (like rewind does on a VCR: return to the beginning). If this isn't what Rewind() does, that's cool (though I don't know then what it does). I just want to get my animated object back to it's starting point. Should I just store the transform and reapply it? (mm.. how do I do that ;-))
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  8. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    gosh, I only want to do something really simple. Maybe my description is making it sound more complicated


    I have an animation that moves X from A to B which I created through the Unity animation UI.

    X: A -------------------> X: B

    At a later time I want X to move back to where it was before the animation (i.e. the starting point A of the animation). I am making the assumption that X is still "under the influence" of the animation - so calling 'Rewind' made sense with that assumption. Maybe that is my error?

    English is my first language so I tend to abuse it! :D
     
  9. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Great timing on this thread... I just ran into this problem earlier today trying to set an animation to a specific frame while also being able to stop it in the same Update and SampleAnimation solved it.

    tomjoad, if you're trying to set the animation back to the start without having to play it again to get to that frame SampleAnimation is your friend.

    Grapes of Wrath is my favorite book :wink:
     
  10. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    Yeah - mine too
     
  11. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    167
    Do we have a solution on this one?

    Cause it's still broken.
     
  12. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    167
    Developers, developers, developers?

    Guys, seriously, I need to rewind my animations! Tried to do that in different ways - the Rewind() doesn't work at all. Period.

    The other way is I just made is this - I wait for animation to finish and then make it go back "realy freaking fast :)"

    Code (csharp):
    1.  
    2.         animation["Default LW Animation"].speed = 2.0f;
    3.         animation.Play("Default LW Animation");
    4.        
    5.         while(animation.IsPlaying("Default LW Animation"))
    6.         {
    7.             yield return new WaitForSeconds(0.1f);
    8.         }
    9.        
    10.         animation["Default LW Animation"].speed = -50.0f;
    11.         animation.Play("Default LW Animation");
    12.  
    13.  
    This one works only for the first time - when I call this again the animation doesn't work at all, it just stays in a static position and doesn't move.

    Here is the next try - I play an animation and then just destroy the GameObject and instantly instantiating the very same prefab again. BUT IT DOESN'T WORK EITHER!!!!! :(((((( When the new GameObject appears on the screen the animation is in its very final position as it has been already played!

    "Please, I need help!" (c) "Serious Man"

    P.S. The rabbi doesn't look busy =\
     
  13. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    167
    gameObject.SampleAnimation(animation.clip, 0); - this one solved the problem, thank you! oh, wait...
     
  14. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    If you have a reproducible case where animation.Rewind doesn't work then please can you file a bug report about it. The last activity on this thread was nearly three years ago - it's possible that the problem was not followed up for some reason.
     
  15. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    167
    yes, for this reason:
    Code (csharp):
    1.  
    2. gameObject.SampleAnimation(animation.clip, 0);
    3.  
    it's always the same (and with me it's also gonna be the same) - the Rewind is broken, but it's ok, I've found a workaround :)
     
  16. fdfragoso

    fdfragoso

    Joined:
    Nov 15, 2010
    Posts:
    35
    The SamplAnimation worked, but only puts gameObject position in the frame 0 of the clip from the animation and the animation does not run backwards (animation.Rewind), so soft (frame by frame) as I need.

    How I could do?
     
  17. xortrox

    xortrox

    Joined:
    Feb 13, 2011
    Posts:
    22
    animation.Rewind() only works when an animation is playing

    animation is basically the animation component attached to the gameObject you are animating, if this gameObject is not playing any
    animations, you cannot use animation.Rewind() cos there will be nothing to rewind
     
  18. Futurebear

    Futurebear

    Joined:
    Jan 11, 2010
    Posts:
    97
    @fdfragoso

    If you want to play an animation backwards, you use negative speeds. so put the speed at -1.

    *I hope I am saying this correctly, been a while since I have used it.*
     
  19. wakerunity

    wakerunity

    Joined:
    Jul 11, 2011
    Posts:
    10
    i find the way,Fast forward to the end of the animation first。


    animation["New Animation"].normalizedTime = 1f;
    animation["New Animation"].speed = -1;
    animation.Play();
     
  20. belias

    belias

    Joined:
    Nov 10, 2011
    Posts:
    35
    thanks wakerunity.
     
  21. gr33nl1nk

    gr33nl1nk

    Joined:
    Dec 19, 2008
    Posts:
    92
    I can do it this way:
    Code (csharp):
    1.  
    2. animation.Rewind();
    3. animation.Play();
    4. animation.Sample();
    5. animation.Stop();
    6.  
     
  22. Kevingarry

    Kevingarry

    Joined:
    May 7, 2012
    Posts:
    2
    Looking for a super 8 camera that will record in reverse, suggestions?
     
  23. jimmysen

    jimmysen

    Joined:
    Aug 30, 2012
    Posts:
    1
    Try any latest model camera
     
  24. JohnyZuper

    JohnyZuper

    Joined:
    Jan 7, 2008
    Posts:
    174
    That worked for me too (in Antares Universe). Thanks!
     
  25. thesfid

    thesfid

    Joined:
    Oct 19, 2010
    Posts:
    12
    This is exactly what I needed. Thank you!
     
    calebmarks likes this.
  26. tiz777

    tiz777

    Joined:
    Jan 20, 2010
    Posts:
    93
    This worked perfectly for me too. Thank you!
     
    sonofbryce likes this.
  27. wtmsuperman

    wtmsuperman

    Joined:
    Jul 11, 2014
    Posts:
    8
    This worked for me too,Thank you!
     
    av_gracevale likes this.
  28. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,059
    This seems to still work in unity 2019.3
     
  29. vladboroday

    vladboroday

    Joined:
    Jan 3, 2018
    Posts:
    5
    unity 2020 Rewind still broken...
     
  30. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,991
    Maybe instead of needlessly necro a post, you could file a bug report if you think something isn't working. Or explain what is it not working for you. Or something.
     
  31. vladboroday

    vladboroday

    Joined:
    Jan 3, 2018
    Posts:
    5
    I've somehow done it using this upload_2021-6-1_16-4-36.png
     
  32. Antonius007

    Antonius007

    Joined:
    Aug 26, 2020
    Posts:
    6
    This also worked in 2021.2.8f1 - thanks for this