Cant get rid of animation delay in Mecanim

Hey, guys! I am trying to get rid of delay when my gameobject goes from state FireFlyStrafe back to state FireFlyIdle. I checked a lot of issues with animation delay but still can’t make my own work as planned. Here’s code I use to control states and pictures of transitions between states. I am flipping strafe animation in my code.

using UnityEngine;
using System.Collections;

public class FiryFlyAnimCtrl : MonoBehaviour {

    private Animator anim;
    bool facingRight = true;
    bool set = false;

    void Start()
    {
        anim = GetComponent<Animator>();
    }


    void Update()
    {

        float move = Input.GetAxis("Horizontal");
       
        anim.SetFloat("SpeedHorizontal", Mathf.Abs(move));

        if (move > 0 && !facingRight)
        {
            Flip();
        }
        if (move < 0 && facingRight)
        {
            Flip();
        }
    }

    private void Flip()
    {
        facingRight = !facingRight;
        Vector3 scale = transform.localScale;
        scale.x *= -1;
        transform.localScale = scale;
    }
}

Hey since you disabled “Has exit time” this should work.

Under your conditions try set less and greater 0 so it will start exactly != 0 and not 0.1.

And why do you use: Mathf.Abs Is there a special reason for absolute values?

anim.SetFloat("SpeedHorizontal", Mathf.Abs(move));

If it still has a delay i would make a bug report to unity about this!

ps: I find it better to declair variables that you always use out of scope.

float move = 0

I would declair it outsite of the Update() scope because of memory alloc. And garbage collect thingis :slight_smile:

Click on the transition, you’ll see two boxes. The top (and left most) is the state you’re transitioning from and the lower one it the target state. Drag the bottom box all the way left until it matches the top one and makes sure under (just below ‘Has Exit Time’) that Transition Duration is set to zero as well.