UMG Spacebar, Enter & Face Button Down all execute "On Pressed"

I’m having some strange behavior with the UMG and On Pressed execution of buttons via the Keyboard and Gamepad (Mouse is not being used). It seems that the Space-bar, Enter key and the game-pad Face Button Down all execute “On Pressed” of any focused button widgets although it appears that none of these keys are bound or in anyway connected to my project Input Action settings. I have tried using Set Input Mode to Game,UI and Game & UI, and they behave just the same.

Tab moves the keyboard focus to the next available focus-able item (left to right) and depending on the UMG setup can move the focus away from the current visible menu/UI, effectively leaving you locked in the menu.

I have also found that all of the keys/buttons listed above do not register as “In Key Events” through the OnKeyDown Override.

I do not want these keys to execute “On Pressed” EVER unless the player has deliberately bound them in the Input settings, but I cannot seem to find any information on why these keys are behaving this way. Does anyone know how I might disable these?

Thanks! :slight_smile:

This is by design. if you don’t want a button or element to be focusable with Tab then edit the “Is Focusable” property of that button or element to false.

If you generally hate the focusing mechanics at all you can also disable them in the “project settings” –> “Engine” –> “User Interface”. Just set the focus property to never.

2 Likes

I was struggling with this earlier today and found out that this behavior is hardcoded in the engine itself. Check how the class SButton (Slate wrapped by the UButton UMG class) and its implementation for OnKeyDown/OnKeyUp functions. You will notice that it checks if the key parameter is related to the EUINavigationAction::Accept.

By going into the implementation of “GetNavigationActionFromKey” (NavigationConfig.cpp), we see that it returns the accept type of navigation when the key is either “Enter”, “SpaceBar” or “Virtual_Accept”.
Finally, in InputCoreType.cpp, the const parameter “Virtual_Accept” is initialized with the function GetGamepadAcceptKeys. This function (GenericPlatformInput.cpp), in turn, returns the key for the gamepad face button bottom.

So, whenever you have a button, it will broadcast press (and click!) events whenever it is focused, enabled and one of those keys have been pressed. Even if you haven’t setup this behavior anywhere in your project.

That being said, making a subclass of SButton that overrides the OnKeyDown/OnkeyUp functions, as well as another class to wrap it up and expose it to UMG (that’s what UButton does to SButton) may be solution to anyone looking for ways to prevent this from happening.

1 Like

Just override the function mentioned here:

https://dev.epicgames.com/community/learning/knowledge-base/P8dV/unreal-engine-slate-customizing-navigation-controls

So it always returns EUINavigationAction::Invalid;

Or try passing to FSlateApplication::SetNavigationConfig() with FNullNavigationConfig in your player controller beginplay