c# - Unity3d - How to get Animator's Layer -->Sub-State --> State namehash? -
i'm using following structure:
(layer) "base layer" --> (sub-state) "jump_fall_roll" --> (state) "roll"
static int rollstate = animator.stringtohash("what put here??"); private animator anim; private animatorstateinfo currentbasestate; void start () { anim = getcomponent<animator>(); } 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....... } }
i tryed every possible combinaison of parents/states namehash, never worked...
the name should in form layer.name, example "base.idle".
animatorstateinfo.isname doc unity
so, why first case not working? , how can second case work??
i'm confused.
edit
screenshot of animator view
i did try static int rollstate = animator.stringtohash("base layer.roll");
then debug.log (currentbasestate.namehash + ", " + rollstate);
will output
1094782407, -1476868190
when i'm in roll state. rollstate never = currentbasestate.namehash.
i did test idle state, works :
static int rollstate = animator.stringtohash("base layer.idle");
i can't see structure sub-states, frustrating.
in up-to-date version of 5.3.4 @ time of writing, question can partially answered follows.
first of all, there no namehash
more. closest variable shortnamehash
. recommended use fullpathhash
instead explained shortly. shortnamehash
bare file name in os, while fullpathhash
, name suggests, contains layer name path before state name. here example use both of them identify current state:
int basestate = animator.stringtohash("base layer.idle"); int short_basestate = animator.stringtohash("idle"); int substate = animator.stringtohash("base layer.jump_fall_roll.roll"); int short_substate = animator.stringtohash("roll"); ... animatorstateinfo s = myanimator.getcurrentanimatorstateinfo(0); debug.log(s.fullpathhash + ", " + basestate); //they equal @ idle state in base layer debug.log(s.shortnamehash + ", " + short_basestate); //they equal @ idle state in base layer debug.log(s.fullpathhash + ", " + substate); //they equal @ roll state in sub-state machine debug.log(s.shortnamehash + ", " + short_substate); //they equal @ roll state in sub-state machine
from above example can see shortnamehash
works bare state name, no matter state regular 1 in base layer, or state in sub-state machine. fullpathhash
works when layer path prefixed before state name. if sure there no duplicate state names in different state machines, shortnamehash
because short, assumption not hold in large complex animator controller, recommend using fullpathhash
time.
i call answer "partial" because have make sure layer id passed getcurrentanimatorstateinfo 0, i.e., "current working layer" (like pwd
command in linux) should base layer. above path name convention fails if pass 1 it. don't have time guess path name should in layer 1. complement in regard welcomed.
Comments
Post a Comment