Clicking on an UMG widget takes the focus for keyboard inputs

Hello,

I’m using an UMG widget for my game’s HUD. It has several buttons. When clicking on a button, then pressing “tab”, it will select the next button/element in the widget. If I keep pressing “tab”, it goes on. Which bothers me, because it means that once the HUD has been clicked somewhere, the keyboard inputs aren’t received by the player controller/pawn.

I tried fixing it, two ways :

  1. Setting the “Can be focused” bool at false. Doesn’t seem to change anything.

  2. Setting up the “Set Input Mode Game Only” node after the widget’s construction. With this enabled (and the player’s controller given as a parameter), I can only input one click/keyboard event, then every mouse input seems locked (EDIT : Actually, some mouse inputs go through. Not a lot, though). This issue might be related to the fact that I handle inputs in the player’s pawn, and not in its controller (since there won’t be any (de)possessing of any sort). I tried to add a hook in the (unused) player controller, and with this “Set Input Mode Game Only” node set, after the initial input, some mouse inputs are received, but a lot of them aren’t (some by the player’s controller, none by its pawn). Note : The keyboard input events are still received.

Any idea where this could be coming from? Is there a third way to prevent the UMG widget to take the focus in any way?

Thanks in advance.

I tested something, and it’s not only related to the tab input. After clicking a button, even pressing the arrow keys will make me navigate in the Uniform Grid Panel (that’s what the buttons are in). I’ll try what you’re suggesting and report back, thanks for your answer !

  1. Can be focused to false should prevent a button from taking keyboard focus, otherwise there is a bug. Make sure you do this for every button
  2. I know that tab / shift tab has a bug currently in 4.12 where it can result in focusing widgets that do not support keyboard focus. I have reported it already. The best thing is to disable tab + shift tab behavior for now. You can overrule the navigation settings that are defined by default. I did that using the following code:

To register your own behavior have a look at the following classes/methods:

SlateApplication.Get().SetNavigationConfig(MakeShareable(new FNavigationConfig()))) 

i use this method in my gameinstance init

FNavigationConfig → defines if you want to respond to navigation requests when a key is pressed

You simply have to derive from FNavigationConfig and overrule virtual

EUINavigation GetNavigationDirectionFromKey(const FKeyEvent& InKeyEvent) const
{
  return EUINavigation::Invalid;
}

This ensures slate never responds to keyboard navigation requests.

Ensure that all the buttons have IsFocusable = false.

Oh well. Pretty sure it comes from that. Let me check it out.

Yes, that was it! Thanks a lot :slight_smile: It didn’t occur to me that I had to do it for each button individually. You’re awesome! Can you edit your original answer to add this suggestion so I can mark it as the correct answer?

Great. Thanks again! Good day to you!

i added it!

And don’t forget to set new keyboard focus, for example, when you switch to SINGLE PLAYER page by clicking or pressing on SINGLE PLAYER button from MAIN MENU page.

Hi there people. If anyone still interested how to do this, I can show my way.

If you save your last focused object to a variable, you can use it for focusing back to it when you lose focus.
For example;
First of all, you should focus your first button on your main menu I guess.

Second, you should highlight all of your buttons or sliders when they are focused.

BUT ! You need to set a variable which holds your last focused object referance. If you focused one of those at button array, you should save it. So when you lose focus, you can get back to it.

The variable to save last widget is a Widget->ObjectReferance

244504-widgetobjectreferance.png

I hope these can help you people.

1 Like

can we use this method to change default key in navigation config?