Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Animator controller transition fires most of the time, but not always

Discussion in 'Animation' started by marzilladev, Jan 24, 2023.

  1. marzilladev

    marzilladev

    Joined:
    Dec 10, 2021
    Posts:
    13
    Hello all.

    I have a state machine where I'm programmatically transitioning a bird back to its idle state from a walking state, using SetInteger and an int value "MoveNumber". The problem is that it only transitions back to idle about 80% of the time. The rest of the time, it gets stuck in the Walking/Move state. Can someone point me in the right direction? Thanks.

    Here is the method controlling the transitions:

    Code (CSharp):
    1. public void SetWalkingAnimation(bool isWalking)
    2.     {
    3.         if (isWalking)
    4.         {
    5.             birdAnimator.SetInteger("MoveNumber", 2);
    6.         }
    7.         else
    8.         {
    9.             birdAnimator.SetInteger("MoveNumber", 1);
    10.         }
    11.     }
    Here's how method is being used:
    Code (CSharp):
    1. controllerManager.SetWalkingAnimation(true);
     
    Last edited: Feb 7, 2023
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    My guess is the logic that controls the "isWalking" bool is getting stuck on true. Either create a Debug.Log() line or make the bool public to check it at runtime and see what's going on.

    Also, it looks like Any State is firing over and over again. Normally when this happens, the animation doesn't even play, maybe Unity modified this in newer versions, not sure; however, you'll probably want to uncheck "Can transition to self" in the Any State -> Move transition.
     
    marzilladev likes this.