Search Unity

Hash from clip name does not match

Discussion in 'Animation' started by sergio93, May 9, 2022.

  1. sergio93

    sergio93

    Joined:
    Aug 28, 2020
    Posts:
    52
    Hello, I am having an issue when trying to keep track of the animation that my character is playing.

    I want to do it using the fullPathHash from

    var m_currHash =
    animator.GetCurrentAnimatorStateInfo(0).fullPathHash


    and compare it with a variable that I previously defined with

    private static readonly int m_hurt = Animator.StringToHash("Character|Hurt")


    Where "Character|Hurt" is the clip name that I can obtain by doing:

    Code (CSharp):
    1. AnimatorClipInfo[] clips = animator.GetCurrentAnimatorClipInfo(0);
    2. foreach (var clip in clips)
    3. {
    4.     Debug.Log(clip.clip);
    5. }
    The problem is that m_currHash and m_hurt do not match when the character is playing the animation. I can only think that the problem is that I am using the wrong string when calling Animator.StringToHash. Maybe because the clip is inside an Sub-State Machine in the Animator?
     
  2. sergio93

    sergio93

    Joined:
    Aug 28, 2020
    Posts:
    52
  3. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    675
    get the hash of state like this ('unarmed' is the sub-state machine)

    hash.JUMP = Animator.StringToHash ("Base Layer.unarmed." + jumpstateName);
     
  4. sergio93

    sergio93

    Joined:
    Aug 28, 2020
    Posts:
    52
    Thanks! That was it