Hello, I am trying to have an in-game menu which pops up with a keypress, and will also close with a keypress.
I have it pop-up no problem via keypress captured from my Controller. And I can close it with a button using the usual remove from parent method.
My problem is the same code on the widget blueprint when originated from a keypress isn’t functioning.
The keypress is captured by overriding the OnKeyDown event, checking for the key (in my case * on numpad), and then calling an Event Dispatcher “Keypress_NumStar” which is bound to an event on the Widget bluprint. I originally just had the close widget nodes in the key down, but was having this issue, so using the Dispatcher to get the code onto the widget blueprint was an attempt (failed) to solve the problem.
I can confirm that the correct code path is occurring. I added the printstring to the exec line on the keypress to be sure that the dispatcher is working correctly and it is.
So with identical nodes on both a button press or key, yet only the button press works, makes me think it’s an issue with focus. Any ideas where to go from here?
Couple more things if relevant:
I have flagged “Is Focusable” on the widget.
I tried get all of class and it only finds the one instance of the widget. Remove from parent on the array didn’t help.
If you do this in the widget itself, well, widget cannot take input events. It’s not really intended to, and binding the keys directly is kind of like circumventing the system. Now, when the widget is removed, what is there to even run the rest of the code?
Input | Unreal Engine Documentation … it might be a bit over the top for now, but at least as a rule of thumb, try to use the input system instead of directly binding the keys.
Great advice JoSf, thanks. I’ll keep my input in the PlayerController. So from PlayerController, I guess I could poll the widgets to see if the InGameMenu was active and if so, remove from parent, and if not, add to view?
Ok, I’m good now, got it working. One final tweak, I had it “set input mode UI only” after adding the menu to the viewport, which was blocking the key. But switching to Game only means losing focus of the widget (I also have mouse buttons on the widget), so “Set input Mode Game and UI” fits the bill. Thanks for your help.
Yeah. You shouldn’t poll though… a reference is all you need, and the engineers at Epic were kind enough to provide an useful boolean for checking the current status of the widget.
Just in case for whom wants to keep using the Set Input Mode UI Only node… (you might need to block input related to in-game logic such as character movement), you can keep your BP as it is and simply override the On Key down event from the desired widget BP, as shown below.
Additionally, by using this method, you can override keys like Tab, which are already predefined to toggle between components within the widget, and make them work according to your own business logic.