Search Unity

Pausing Mecanim

Discussion in 'Animation' started by MrDude, Apr 23, 2015.

  1. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Here is my latest situation...

    I have a parallax animated background that plays out over 15 seconds before repeating. My character runs up, and stops so I want the animation to stop also. When my character runs on to the next waypoint, I want the animation to continue playing. When he reaches his net destination, the background animation stops also.

    Is there any way at all to tell Mecanim to stop playing a clip and just pause? Not that I have seen.

    In the legacy system it was possible to set an animation's position manually using the normalisedPosition parameter. It seems in Mecanim that is not possible.

    I saw there is something that sounds similar in there already in the form of StartPlayback() and playBacktime but from the looks of things it looks like you first have to play the entire animation once, store it in memory, then scrub through it from there... I can't very well play a 15 second clip at the start of every scene just to capture it in memory and then say "Okay, people, now we can start playing"...

    In past I was able to let this go but now it seems I am forced to code each layer's UV animation manually because Mecanim simply doesn't have a means of stopping or pausing an animation so I think it's time to ask for some help. I was thinking it might have a means for me to set the current animation's speed to 0 but I an't seem to find a way to do that via code either...

    Can someone please help me out? Is there any way to make an animation simply pause... and continue playing when I choose... instead of simply playing forever automatically?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    You are looking for
    http://docs.unity3d.com/ScriptReference/Animator-speed.html

    Set animator speed to 0 to pause, and set it back to 1 for normal playback.

    this is for recording a sequence of animation which you can rewind or playback in game.
     
    WhiteGfx, codestage and theANMATOR2b like this.
  3. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Thanks, man. I was looking for Animator.speed in all the wrong places... My intention was to do that and then I couldn't find it :D

    As for the recording stuff so you can rewind it in game, that sounds like time control like in Prince Of Persia. That never came across in the docs so that is also good to know it's in there if I ever need it.

    thanks
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Exactly like Prince Of Persia Sand of time ;)