Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Whats wrong? I re typed the entire thing three times

Discussion in 'Scripting' started by BLQQD1, Jul 13, 2022.

  1. BLQQD1

    BLQQD1

    Joined:
    Dec 5, 2019
    Posts:
    4
    Following a simple youtube tutorial

    COde is at 9:40
    Retyped the running part of the script 3 times but always get an error saying;

    Parameter 'Hash 1239866031' does not exist.
    UnityEngine.Animator:GetBool (int)
    animationStateController:Update () (at Assets/animationStateController.cs:27)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class animationStateController : MonoBehaviour
    6. {
    7.     Animator animator;
    8.     int isWalkingHash;
    9.     int isRunningHash;
    10.  
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         animator = GetComponent<Animator>();
    16.  
    17.  
    18.         isWalkingHash = Animator.StringToHash("isWalking");
    19.         isRunningHash = Animator.StringToHash("isRunning");
    20.  
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.         bool isWalking = animator.GetBool(isWalkingHash);
    27.         bool isrunning = animator.GetBool(isRunningHash);
    28.         bool forwardPressed = Input.GetKey("w");
    29.         bool runPressed = Input.GetKey("left shift");
    30.  
    31.         if (!isWalking && forwardPressed)
    32.         {
    33.             animator.SetBool(isWalkingHash, true);
    34.         }
    35.         if (isWalking && !forwardPressed)
    36.         {
    37.             animator.SetBool(isWalkingHash, false);
    38.         }
    39.         if (!isrunning && (forwardPressed && runPressed))
    40.         {
    41.             animator.SetBool(isRunningHash, true);
    42.         }
    43.         if (isrunning && (!forwardPressed || !runPressed))
    44.         {
    45.             animator.SetBool(isRunningHash, false);
    46.         }
    47.     }
    48. }
    49.  
    1st day playing with unity in a long time with basically no experience. I'd really appreciate an explanation, Thanks for you time
     
    Last edited: Jul 13, 2022
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Instructions on how to properly post code are stickied to this sub forum.

    In any case, does your animator have properly set up conditions?
     
    Bunny83 likes this.
  3. BLQQD1

    BLQQD1

    Joined:
    Dec 5, 2019
    Posts:
    4
    Tbh I have no idea
    The walk animation works just fine, adding the run part of the script brings the error and nothing happens when I press shift
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Well I would have no idea on my end either. That's for you to investigate.
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,572
    Are you sure you have actually created both parameters like he did at 08:27? You're probably missing one or both. Your code tries to access those by name. So the possible issues are:

    • You forgot to create those parameters in your animation
    • You may not use the right animator
    • You may have misspelled any of those parameters, either in the animator or in your code.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    I recommend instead that you type it one time but type it CORRECTLY.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!


    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!