3
\$\begingroup\$

So with the new Animator system, Unity has smartly allowed us to pre-hash the strings for looking up variables within the Animator state machine, using the Animator.StringToHash static method. This lets us access the animator variables every frame without needing to perform hashing calculations each time, allowing a nice optimization.

What I'm wondering is if there is any way to do the same for the Input.GetAxis method, since it isn't overloaded with an Integer parameter option, it seems there is not, but I wanted to confirm that.

Am I overestimating the performance boost, and is there another method for accessing inputs in a faster manner?

\$\endgroup\$
  • \$\begingroup\$ Generally you're checking each input button/axis only once or a small handful of times each frame, so the hashing costs don't add up the same as if you have 100 NPCs in a crowd all updating their animations. You can limit this to exactly once each frame by adding an intermediate script that grabs inputs and caches them for later scripts to query using your own hashless path. But I think at this point your best bet is to look forward to the new input system rolling out in an upcoming version. \$\endgroup\$ – DMGregory Dec 2 '18 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.