title: Unity3d - How to get Animator's Layer -->Sub-State --> State namehash?
body: <p>I'm using the following structure:</p>
  
  <p>(Layer) "Base Layer" -->
     (Sub-State) "Jump_Fall_Roll" -->
        (State) "Roll"</p>
  
  <pre><code>static int rollState = Animator.StringToHash("What to put here??");
  
  private Animator anim;
  private AnimatorStateInfo currentBaseState;
  
  void Start ()
  {
      anim = GetComponent&lt;Animator&gt;();
  }
  
  void FixedUpdate ()
  {
      currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
  
      if (currentBaseState.nameHash == rollState) {
          Debug.Log ("ROLL nameHash worked"); //Not working
      }
      if (currentBaseState.IsName("Roll")) {
          Debug.Log ("ROLL IsName worked"); //Working.......
      }
  }
  </code></pre>
  
  <p>I tryed every possible combinaison of parents/states for the nameHash, but it never worked...</p>
  
  <blockquote>
    <p>The name should be in the form Layer.Name, for example "Base.Idle".</p>
  </blockquote>
  
  <p><a href="http://docs.unity3d.com/Documentation/ScriptReference/AnimatorStateInfo.IsName.html" rel="nofollow noreferrer">AnimatorStateInfo.IsName doc from Unity</a></p>
  
  <p>So, why is my first case not working? And how can the second case work??</p>
  
  <p>I'm really confused.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Screenshot of my Animator view
  <img src="https://i.stack.imgur.com/8Q9s1.jpg" alt="Screenshot of my Animator view"></p>
  
  <p>I did try <code>static int rollState = Animator.StringToHash("Base Layer.Roll");</code></p>
  
  <p>Then <code>Debug.Log (currentBaseState.nameHash + ", " + rollState);</code></p>
  
  <p>Will output </p>
  
  <blockquote>
    <p>1094782407, -1476868190</p>
  </blockquote>
  
  <p>When I'm in the roll state.
  rollState NEVER = currentBaseState.nameHash.</p>
  
  <p>I did test this with the Idle state, which works perfectly like this :</p>
  
  <p><code>static int rollState = Animator.StringToHash("Base Layer.Idle");</code></p>
  
  <p>I can't see what the structure is for sub-states, really frustrating.</p>