basically I have a seperate scene for main menu, with a canvas that has 2 buttons, play and exit. I know that when you create a canvas, it comes with EventSystem gameobject, and there you can select which actions asset will be used and all that, and I also set up basic navigation with arrow keys and W/S. I have also set up each button so that when onClick is called, a simple debug.log is fired.
What I can’t wrap my head around is that for click action there are only 2 bindings in my UI map, left button (mouse) and space (keyboard) Yet somehow every time one of the buttons is selected and i press Enter, the OnClick method fires anyway, even though again, Enter isn’t on the UI map.
Also, while left click works just fine, space key doesn’t. the OnClick method is only called when I am hovering over a button and then press space. I would like it to be independent of the mouse position, if that makes sense, so that a player could be able to navigate with arrow keys and “click” with space key, even if there is no mouse involved.
You should not remap standard UI button behaviour for standard buttons. SPACE is not a UI confirmation key, ENTER is. This is hardwired, for good reason, since applying non-standard input goes against expectations.
SPACE only working while the mouse hovers over the button, this means the button isn’t the “selected” UI element. Think of a Checkbox + Apply button next to it. While you press SPACE the checkbox may toggle but to send SPACE to the button, you would have to press Tab or arrow keys to navigate the selection to the button element. That’s what the mouse hover does.
You can use a script to select the button: EventSystem.current.SetSelectedGameObject(theButton);
FWIW please start with the default Input Action Map. It already defines all the standard keys for player controls and UI. This then automatically provides you with the navigation of UI elements eg arrow keys or DPad to select the next/previous element.
It shouldn’t be hard wired. It should be down to the inputs set up in the event system input module.
At least in UI Toolkit land, the Submit input is fully controlled by the input define on said component. If that’s not the case in uGUI then I think that ought to be fixed.
And honestly, in any WASD based game, Spacebar or E is a better option for submit than Enter is.