Search Unity

Restart animation clip from within state in Mecanim

Discussion in 'Animation' started by FGRivera, Dec 3, 2013.

  1. FGRivera

    FGRivera

    Joined:
    Jun 3, 2013
    Posts:
    16
    Is there an easy way to restart an animation clip in mecanim from the state that plays that clip?

    Basically I have a shoot animation that I want to reset every time the fire button is pressed, and doesn't exit until the button is not pressed for the specified exit time.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I might try this: drag your firing clip into the Animator twice, making two different states out of it (let's call them "fire1" and "fire2"). Hook up the transitions so that when the fire button is pressed in fire1, it goes to fire2, and vice versa. Then of course you have each of them exit at the appropriate time back to idle or whatever.

    To answer your question directly, no, I don't know any way to make a transition from a state to itself — but this hack might be nearly as good.

    An alternative would be to make a "refiring" animation, very short, that you go to from your firing state when the fire button is pressed again. This refiring state would exit very quickly back to the firing state.

    HTH,
    - Joe