Search Unity

Hash does not exist

Discussion in 'Scripting' started by masterbuilder335, Apr 9, 2021.

  1. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Code (CSharp):
    1. IsTalkingHash = Animator.StringToHash("IsTalking");
     
  2. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Code (CSharp):
    1. bool tPressed = Input.GetKey("T");
     
  3. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Code (CSharp):
    1. if (tPressed)
    2.         {
    3.             animator.SetBool(IsTalkingHash, true);
    4.         }
    5.         else
    6.         {
    7.             animator.SetBool(IsTalkingHash, false);
    8.         }
     
  4. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    the last bit of code is where it says it doesn't exist
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    Not sure why you needed 4 posts to say that.

    ...

    Question... are you certain that the bool parameter "IsTalking" exists on that 'animator'?

    If you change the SetBool calls to:
    Code (csharp):
    1. animator.SetBool("IsTalking", true);
    Does it work?

    Lets rule out if hash has anything to do with it at all...
     
    Olmi, Kurt-Dekker and Joe-Censored like this.
  6. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    I messed around with the code to see if some things work and it still says it doesn't exist
     
  7. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AnimationState : MonoBehaviour
    6. {
    7.     Animator animator;
    8.  
    9.     int IsRunningHash;
    10.  
    11.     int IsTalkingHash;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         animator = GetComponent<Animator>();
    17.  
    18.         IsRunningHash = Animator.StringToHash("IsRunning");
    19.  
    20.         IsTalkingHash = Animator.StringToHash("IsTalking");
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.         bool forwardPressed = Input.GetKey("w");
    27.         bool leftPressed = Input.GetKey("a");
    28.         bool downPressed = Input.GetKey("s");
    29.         bool rightPressed = Input.GetKey("d");
    30.         bool tPressed = Input.GetKeyDown("t");
    31.         bool tNotPressed = Input.GetKeyUp("t");
    32.  
    33.         if (forwardPressed || leftPressed || rightPressed || downPressed)
    34.         {
    35.             animator.SetBool(IsRunningHash, true);
    36.         }
    37.         else
    38.         {
    39.             animator.SetBool(IsRunningHash, false);
    40.         }
    41.  
    42.         if (tPressed)
    43.         {
    44.             animator.SetBool("IsTalkingHash", true);
    45.         }
    46.  
    47.         if (tNotPressed)
    48.         {
    49.             animator.SetBool("IsTalkingHash", false);
    50.         }
    51.  
    52.     }
    53. }
     
  8. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,011
    Look, you asked a question because you have an issue. Lordofduct gave you a specific change you should try. If that doesn't work as well, your issue is most likely that the animator you're using does not have a parameter called "IsTalking". If that's the case there is nothing you can do on the code side to make it work. You have to look at your animator first.

    ps: You know that you can edit your posts? Please stop posting such micro-fragments as seperate independent posts.
     
    Kurt-Dekker and lordofduct like this.
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    You didn't answer my questions though.

    If you'd like help we're going to need more information.

    I see you actually attached more code for context, but as Bunny83 pointed out... we need to rule out that the animator just isn't configured correctly or not. And like they said... if it's that, there's no amount of code that can fix that.
     
  10. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Sorry, so if you look at the code I put what you told me and it didn't work, and the reason I made a bunch of posts was because it wouldn't work when I put all those code fragments together in one post, and yes I am certain that the "IsTalking" parameter is in the animator
     
  11. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    This is the proof that the animator has the parameter "IsTalking"
     

    Attached Files:

  12. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69
    Is there a better way to upload a picture?
     
  13. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    69