- Home /
Animator HashToString returns 0
I have an Animator set up with 4 parameters. The Animator and the Script are attached to an active game object (Player Character).
ForwardVelocity (A Float) AngularVelocity (A Float) VerticalVelocity (A Float) Jump (A Trigger)
When I run the following code, I get a debug log of 0 0 0 0
int forwardHash;
int angularHash;
int verticalHash;
int jumpHash;
void awake(){
forwardHash = Animator.StringToHash ("ForwardVelocity");
angularHash = Animator.StringToHash ("AngularVelocity");
verticalHash = Animator.StringToHash ("VerticalVelocity");
jumpHash = Animator.StringToHash ("Jump");
}
void Update(){
Debug.Log (forwardHash + " " + angularHash + " " + verticalHash + " " + jumpHash);
}
I'm working through this as well and I am getting 0. One thing I noticed is that you should probably put the Layer name in front.
forwardHash = Animator.StringToHash("Base Layer.ForwardVelocity");
the parameter must be wrong, it's working for me (the stringtohash) i guess you must have typo or there's no state named "Base Layer.ForwardVelocity"
Answer by Baste · Dec 09, 2014 at 05:28 PM
StringToHash gives you hashes for the names of the states in the animator. So if you have an animation state named "Running", Animator.StringToHash("Running"), you're getting the hash for the running state, not the parameter.
Anyways, there's nothing meaningful you can do with the hashes of your parameters - they can only be used through their string names - so I have no clue why you'd actually want this.
oh and the values are 0 because your Awake method isn't being run, since you named it "awake" instead of "Awake".
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Animation in Unity 4.3 0 Answers
how to pass parameters to single animation 0 Answers