Animation Transitions: Reverting to original state

Hi guys,

I am having an issue with the Animator (controller). I structured a pretty plain state machine (currently having a transition from an idle animation to a spell animation). The way the transition is controlled is through SetInteger. In my script, at some point, I SetInteger to 1. This plays the animation as expected. However, when the “spell” animation finishes playing and it goes back to idle, it replays the same sequence of states over and over again (basically loops idle-spell-idle-spell-etc.).

How am I going to revert to the original idle animation only until commanded otherwise? If I were to use a timer to find when the animation finishes and then SetInteger back to 0, I wouldn’t use the animator, which is supposed to handle this stuff automatically.

The problem might stem from the way I set up the transitions, so, based on the problem, if you can estimate where the answer might lie, let me know! Thank you in advance for your help.

First of all I don’t have any idea why do you use integer with only 2 different states? That doesn’t really matter that much but it would be logically to use bool for 2-states, moreover for your case I’d use Trigger instead - it autoresets itself to false state after being used (isn’t that what you need?).

Now closer to the point. If for some reason you don’t want to use trigger then your spell’s “spell animation” should set your integer back to 0:

private void Update()
{
    if (yourAnimator.GetCurrentAnimatorStateInfo(0).IsName("SpellAnimation")) yourAnimator.SetInteger("SpellInteger", 0);
}

There is one more way of setting float variable public or [SerializeField] and animate it via your animation but then again on Update you’ll need to check it ~like that:

private void Update()
{
    if (stateFloat > 0.9) yourAnimator.SetInteger("SpellInteger", 0);
}

But then again why not just use Trigger?