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

Character does not change animation

Discussion in 'Documentation' started by cags099, Jan 19, 2021.

  1. cags099

    cags099

    Joined:
    Jan 16, 2021
    Posts:
    6
    I am learining unity, and i followed BlackThornProd's tutorial (
    )

    My script and character settings are exactly the same, and yet it doesn't change animation

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CharacterAnimation : MonoBehaviour
    6. {
    7.     private Animator anim;
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         anim = GetComponent<Animator>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)) {
    19.             anim.SetBool("isRunning", true);
    20.         } else {
    21.             anim.SetBool("isRunning", false);
    22.         }
    23.     }
    24. }
    25.  
     
    TheJudge7788 likes this.
  2. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    320
    Is the correct animator assigned on the character In the inspector?

    If you look at the animator and parameters while playing. You should see the booleans check box toggle on and off while you run and use your code. Does that happen?

    If not, If you put print or debug.log statements do we know for sure the anim.set bool line is getting called?

    If its getting called and the parameters still aren't updating in front of you in animator/parameters, double tripple check the spelling and letter caseing is identical. I do that sometimes in parameters, lower case letter wrong or whatever.

    Any warnings or errors?
     
  3. cags099

    cags099

    Joined:
    Jan 16, 2021
    Posts:
    6
    There are no warnings nor signs, and the runnig box does not change over time, only idle changes. The animation runs smoothly, but when its time to move the character the animation does not change. They are not getting called :(

    As far as this question, I'm sorry to say I don't understand "If not, If you put print or debug.log statements do we know for sure the anim.set bool line is getting called?" How do I put the Debug.log on the script to check it out?
     
  4. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    320
    Inside the if statements, or anywhere you want to, type

    Code (CSharp):
    1. print("hello, my name is nick");
    And look in the console for it to read out.
    Its used to know if that area od code is even being called at all
     
  5. cags099

    cags099

    Joined:
    Jan 16, 2021
    Posts:
    6
    It shows nothing ._.
     
  6. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    320
    good, so you have started to narrow down the problem.

    The code seems to be correct, but even so, to check that everything is working

    Code (CSharp):
    1.       if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
    2.         {
    3.             print("hello");
    4.             anim.SetBool("isRunning", true);
    5.         }
    when you play this scene. You should be reading out the print statement "hello" only when holding left or right arrow keys.
    Are you sure that is not happening?

    here is a picture of the console from google. Look at the bottom of your project (if default layout) and the cartoon word bubble in the top right of this pic that says 2.... click it,
    you should be reading many print statmets as you are holding left and right arrows.

    If not, try to print inside the Start function.
    If nothing ever reads out anywhere then maybe you never assigned this script to anything in the first place


     
  7. cags099

    cags099

    Joined:
    Jan 16, 2021
    Posts:
    6
    I fixed it, don't know how but suddenly it began working, didnt change a thing... so... who knows what happened. Thanks for the help :)