Animation Double Proc


I’ve done some searching on this topic and found nothing that could lead to a solution (the most likely one being “it’s buggy right now”).

The situation is simply that I have a bool requirement for switching between animation states. The script (which uses OnButtonDown, I did research the issue) simply toggles the Animator’s booleans and switches back to the idle state after an IEnumerator yield WaitForSecondses for the duration of the animation.

However the animation plays twice. The second time, the boolean on the left side of the Animator window is clearly unchecked, but it triggers a second time. I wouldn’t even mind visually, but the lack of consistency between the boolean’s value and what is happening could easily cause issues later on.

Any insight is appreciated!

P.S.: This might not be relevant, but as a side note I have managed to make it work “sort of”. That is, with the animation (the one that is double played) having its speed set to 0.5, it plays only once. However I don’t get why, nor do I really want that extra layer of finnicking to find where things will line up instead of using clearly marked timestamps.

U should use trigger instead of this all stuff :slight_smile:

Edit: Arrange your animations states in this way so it gets a entry state and exit state . Next deselect the
“Has exit time” in Inspector while selecting the transition arrow ,like i have deselected it between Still state and Attack State . This prevents it from looping and cuts the animation in between.And one last important and best this is go find the animation clip and in Inspector make sure you have deselected the loop.(Only for animations which you dont want to get loop like my Attack State Animation clip have no loop while the Still Animation Clip have Loop .) 60331-q.png

int TriggerHash = Animator.StringToHash("myTriggerNameFromAnimatorWindow") ;
int animationHash = Animation.StringToHash("Base Layer.Run") ;

Animator _animator ;
private AnimatorStateInfo stateInfo ;

void Awake()
    _animator = GetComponent<Animator>();

void Update()
    stateInfo = _animator.GetComponentAnimatorStateInfo(0) ;
    if (Input.GetKeyDown (KeyCode.X))
        _animator.SetTrigger(TriggerHash) ;

U should Look more deep in learning - Every basic is provided in Unity Tutorials

Check here : Your Problem gets Solved in this tutorial