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

is that possible to get "AnimatorStateInfo.fullPathHash" in editor ?

Discussion in 'Scripting' started by canis, Apr 7, 2020.

  1. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    what I'm doing is the combo system for my game.
    in order to locate the target state during runtime.

    so I was tried to fetch the AnimatorState data in Editor as following
    Info : I was locate the target "AnimatorControllerLayer" within the "AnimatorController" from "Animator"
    Code (CSharp):
    1. private void CacheStateMachine(AnimatorStateMachine asm)
    2. {
    3.     foreach (ChildAnimatorState child in asm.states)
    4.     {
    5.         AnimatorState state = child.state;
    6.         if (!stateHashDict.ContainsKey(state.nameHash))
    7.             stateHashDict.Add(state.nameHash, state.name);
    8.         else
    9.             Debug.LogError($"Key[{state.nameHash}] already exist, between {stateHashDict[state.nameHash]} vs {state.name}", comboUnit.gameObject);
    10.     }
    11.     foreach (ChildAnimatorStateMachine state in asm.stateMachines)
    12.     {
    13.         CacheStateMachine(state.stateMachine); // recursive pattern
    14.     }
    15. }
    however the "AnimatorState" above just give me the "AnimatorState.nameHash" which is the hash from state name without parent path...

    as result it didn't match the "AnimatorStateInfo.fullPathHash" at runtime.
    so is that any way to work around ?!
     
  2. KevinCastejon

    KevinCastejon

    Joined:
    Aug 10, 2021
    Posts:
    89
    I'm looking for the same thing
     
  3. KevinCastejon

    KevinCastejon

    Joined:
    Aug 10, 2021
    Posts:
    89
    I finally managed to access AnimationClip hashcode from editor with Animator.StringToHash(clip.name)
     
    canis likes this.