Search Unity

Animation doesn't change on bool change

Discussion in 'Animation' started by rschock, Jan 7, 2021.

  1. rschock

    rschock

    Joined:
    Nov 2, 2020
    Posts:
    2
    Hey,
    I have a simple state machine with three variables, but I can't get the animation to change for the sake of it. When I start the game the idle animation plays, but when the animation booleans are changed (and I know they are, as I'm logging them with e.g. anim.GetBool("isIdle")) the model still plays the idle one. All the correct clips are on the states, and "has exit time" is also ticked off everywhere. Don't know what to do really.

    2021-01-07_19h35_32.png
    2021-01-07_19h46_26.png
    Code (CSharp):
    1. protected readonly string idleAnimation = "isIdle";
    2. protected readonly string walkingAnimation = "isWalking";
    3. protected readonly string runningAnimation = "isRunning";
    4. ...
    5.  
    6.     void Start()
    7.     {
    8.         ...
    9.         anim = GetComponent<Animator>();
    10.     }
    11.  
    12.  
    13. protected void SetAnimationStatus(string status)
    14.     {
    15.         if (status.Equals(idleAnimation))
    16.         {
    17.             anim.SetBool(walkingAnimation, false);
    18.             anim.SetBool(runningAnimation, false);
    19.             anim.SetBool(idleAnimation, true);
    20.         }
    21.         else if (status.Equals(walkingAnimation))
    22.         {
    23.             anim.SetBool(idleAnimation, false);
    24.             anim.SetBool(runningAnimation, false);
    25.             anim.SetBool(walkingAnimation, true);
    26.         }
    27.         else if (status.Equals(runningAnimation))
    28.         {
    29.             anim.SetBool(idleAnimation, false);
    30.             anim.SetBool(walkingAnimation, false);
    31.             anim.SetBool(runningAnimation, true);
    32.         }
    33.     }
    34.  
    35. ...
    36.  
    37. void Update()
    38.     {
    39.         SetAnimationStatus(walkingAnimation);
    40.     }
    And even if the states are updated, its always only the damn idle animation!

    2021-01-07_19h43_13.png

    Maybe the solution is simple, but I honestly wasted already so many hours searching that I'm becoming desperate.
     
  2. rschock

    rschock

    Joined:
    Nov 2, 2020
    Posts:
    2
    I found my very doofus answer btw., which none of you could've seen because it wasn't in the provided code: I used protected static Animator anim;, which broke the logic quite a bit. Still thanks to those who at least tried to look into it.