How to disable all keyboard inputs except for one when widget is added to viewport?

Hello. How would you go about creating an Esc menu (for example) that will disable all keyboard inputs except for one so that the player can press Esc again to close the menu? Using Set Game Paused and setting Execute when Paused to true in the InputAction is NOT one of the solutions I’m looking for.

I’m trying to refrain from having to disable each key one at a time with a combination of bools and branches if there is a better way and using Disable Input or Set Input Mode UI Only blocks all keyboard events so I can’t listen for a specific key further down in my code. I also tried to also override the Key Down function in my widget BP but that doesn’t work because of the blocked events. C++ answers are welcomed too.

Hi man,
I dont know if there is a better solution,
i often use dirty tricks XD

Just disable the input for your char/actor or unpossess it,
and use the level blueprint , or create a dedicated actor, to listen to the input you need.

Is really draft, but in your level blueprint you could also, check if the actor is “Deactivated” and take more complex decision…

​​​​​The unpossess current pawn and create another pawn to possess seems like a viable strategy for me. I don’t want to go the level BP route because then I have to put the logic in every level. Now I just have to do it in a way that possessing the new pawn keeps the same camera position as my unpossessed pawn so that bringing up the menu doesn’t suddenly switch camera positions. Thanks.

I don’t really understand the question.
Even with default setups the input when UMG is displayed and set to UI only doesn’t affect the game input.

If you override key down event and kill it (use a return? I don’t recall how to do it exactly because it’s normal to do the opposite. Making sure the event is not killed but passed on).
you’ll also get no input at all…

So overriding the OnKeyDown function does work, I was missing an element. I fixed my mistake and now it works. My solution:

Make sure Is Focusable is set to true in your widget’s details panel.

widgetimg2.PNG

After adding to viewport, use the Set Input Mode UI Only and connect your widget to focus (which was what I was missing).

widgetimg1.PNG

Finally override the OnKeyDown function in your widget to listen for your desired key.

This will make it so all input to your character is disabled when your menu appears but you can press the same menu button again to close it and without pausing the game world.

5 Likes