How to prevent axis input from triggering "ui_down" input action multiple times

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

In Project Settings > Input Map, the “ui_down” action is the action used by Godot’s native UI system for navigating downwards in whatever UI you are creating. Similarly for “ui_up”, “ui_left”, and “ui_right”.

Currently, I have “ui_up” mapped to the up key on the keyboard, dpad up on controller, and left stick up on controller. My menu is simply a collection of buttons arranged vertically. On load, the topmost button is selected and the user can navigate up or down.

Keyboard and controller dpad work fine, as they are digital button presses. Left stick up, however, is an axis, and so when you press it while on the menu, you simply fly through all the buttons in the menu, every tick of update.

So my question is, what’s a good way to keep “ui_up” mapped to joystick axis, but prevent flying through menus because of the analog input? Does Godot offer a simple way to do this out of the box, or do I need to do some custom scripting?

:bust_in_silhouette: Reply From: Arkinum

Don’t know if anyone has a better solution but I would cheat the system by:

-Put a timer node somewhere that makes sense
-Connect the timer nodes timeout signal to the input script
-Make a bool variable, like ‘canmove = true’
-Set the timers time to something short like 0.3 seconds or so (or shorter, play around with it)
-Nest the input under the ‘if canmove == true:’ condition
-Nest and set ‘canmove’ to false under the input code and start the timer.
-Set the signal time out function to change the ‘canmove’ to true when finished

Not sure if this will work with your setup, but anyway.

Edit: had to reformat a little

:bust_in_silhouette: Reply From: haha-lolcat1

I think what you described is a bug in v3.4: UI focus change is triggered too often when using gamepad analog stick to navigate menus (does not occur with D-pad or keyboard) · Issue #54959 · godotengine/godot · GitHub

Try Arkinum’s workaround above, otherwise you might have to avoid using the analog stick for ui navigation for now.