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 :
Setting the “Can be focused” bool at false. Doesn’t seem to change anything.
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?
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 !
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
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:
Yes, that was it! Thanks a lot 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?
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.
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.