Using hash

It’s a micro-optimization, but it also isn’t hard to use in any way, so it’s probably a gain.

I’ve set up a file that just caches all Animator hashes used in the game, which looks like:

public static class AnimatorNames {
    public static int Attack = Animator.StringToHash("Attack");
    public static int Idle   = Animator.StringToHash("Idle");
    //etc
}

Which means that instead of doing myAnimator.SetTrigger("Attack");, I do myAnimator.SetTrigger(AnimatorNames.Attack);.

This has the added benefit of having a centralized place where all strings used are listed, meaning that if you’re looking at an AnimatorController and are wondering where it’s triggers and bools are used, you have a single place to check.[/Code]

4 Likes