Does anyone have a link to some tips of how to clean the code up? If only for sanity as it’s getting painful having to set each one when I introduce new events for the character (and I miss one).
That’s because they’re strings, Animator actually uses integers to change it’s variables, when pass a string a conversion happens and an integer is generated which passed to the animator, what you can do is cache animator’s variable.
int isSneaking;
int isWalking;
int isJumping;
void Start(){
isSneaking = Animator.StringToHash("isSneaking");
isWalking= Animator.StringToHash("isWalking");
isJumping= Animator.StringToHash("isJumping");
}
void Jump(){
m_playerAnim.SetBool(isJumping, false);
}
Further more, these lines you shared, where are you using them?
The thing I was about to tidy up/optimise (for my own sanity!) are the several states where a button is pressed and I am passing each SetBool etc in each if statement … ?
I’ve just used these as a staging thing and was always going to get around to doing them properly at some point. Maybe create a function passing back the variables to a single bool run through
There are roughly seven or eight of these (at the moment):
From what I see you’ve set a bool to true and passed it on to the animator and it’s not changing to false, If that’s the case don’t create that bool just pass true, further more you don’t need to set animator’s parameters every update, change them only when you need to.