Animating currently selected UI elements with multiple input methods

How many buttons do you have on at once?!

ALSO: DO NOT OPTIMIZE CODE JUST BECAUSE… If you don’t have a problem, DO NOT OPTIMIZE!

If you DO have a problem, always start by using the profiler:

Window → Analysis → Profiler

Failure to use the profiler means you’re just guessing, making a mess of your code for no good reason.

https://discussions.unity.com/t/841163/2

Notes on optimizing UnityEngine.UI setups:

https://discussions.unity.com/t/846847/2

If I had to guess, the bottleneck would NOT be accessing EventSystem.current but rather issuing scale change assignments when they are not in fact changing, which likely triggers a UI geometry rebuild. You could trivially update my script to not issue scale changes unless they are different than the previous frame, probably 3 lines of code total.

You can implement callbacks like Grozzler suggests above, but in my opinion I find those things ALWAYS have bizarre fragile side effects, such as failing when the user drags their finger off the edge of the screen, or the user turns off the device when his finger is in contact with the screen, or even simpler stuff like a scene change happens and the user’s finger was already down, flaky edge stuff like that. That’s why I favor a polled approach, but YMMV.

1 Like