Unreal Engine Tips: How to use Keyboard Inputs when Input Mode is set to UI Only

I had recently migrated some of the HUD workflow from Prototype Menu System to Tower Defense Starter Kit. While going through the HUD blueprints, I noticed that the Input Mode was being set to Game and UI when activating the Pause Menu. Since I didn't want the player to have the option to interact with the game outside of the menu in this state, I went ahead and changed it to UI Only, only to find out that the Escape button could no longer be used to quit the Pause Menu (in spite of it being set to Execute when Paused). It turns out that setting the Input Mode to UI Only also prevents us from interacting with the UI using keyboard.

At first, it seemed like I'd have to revert it back to Set Input Mode Game & UI. But further inspection led to a workaround to tackle the issue: Handling the keyboard input directly through the widget itself instead of the player controller.
 
The first step is to ensure that the widget can be focused. We can do this by setting its IsFocusable attribute to True.


Next we need to make sure that the widget has keyboard focus, which can be easily achieved by calling the Set Keyboard Focus function in the Event Construct of the widget. This will enable the widget to receive keyboard inputs.


With that taken care of, all that's left is to override the widgets' default keyboard input response. So we'll override its On Key Down function and add the required logic. For example, in my project, that involves unpausing the game as shown below:


 
And that's all there is to it. You should now be able to interact with your widgets using the keyboard even when the Input Mode is set to UI Only.
 
I'll also be adding these changes to the Prototype Menu System in the next update. So it should be available on GitHub soon.

Comments

  1. Thanks man helped me alot I used a system like this for changing Chat-Rooms when already in text field by pressing [Tab]

    ReplyDelete
  2. Благодарю за прекрасный гайд

    ReplyDelete
  3. what is the name for node after get key?

    ReplyDelete

Post a Comment