Gamepad Controller for UMG

Hi Guys,

Currently I’m learning UMG. I want to create a UMG Menu similar with ShooterGame Menu. But I’m having difficulties in binding key to navigate menu items.
In ShooterGame Menu, we can select menu item with gamepad controller and keyboard. Logically, it unbinds all key input related to game and binding key input just for the UI. Although ShooterGame uses Slate, I think it will be similar for UMG. From what I observed, ShooterGame Menu is an array of MenuItem class. So navigating the menu list is similar to navigating array element.

Before going any further I just want to check how UMG handle binding. I created a simple Menu along with its Menu level. I created a simple blueprint to show the Menu on the Level.

My first idea is to detect the input key on the UMG, and binding it to navigation keys.
However I couldn’t find any key event (except the mouse and touch) on the UMG.
For example, if I click Down on my keyboard and in my Gamepad, it will navigate to the next menu item. There is only onclicked event which is for Mouse click.

  • How can I use the onclicked event for keyboard or gamepad, and get the button behavior like clicking button using Mouse?
  • Also, how to set button behavior to be hovered when a button is selected using keyboard or gamepad (selected button), like the button is hovered by mouse?

Thank you very much in advance for your help.

Also, from what I learnt (CMIIW), Set Input Mode UIOnly ignore all input except the mouse input. At first, I thought that Set Input Mode UIOnly ignore all keybindings for game play and then I can put new key bindings for UI, but so far I couldn’t figure out how.
So, I prefer to use Set Input Mode UI and Game.

Solved!!

I found out that UserWidget has a OnKeyDown (a BlueprintNativeEvent function). So I implemented OnKeyDown on Widget Blueprint then connect it to Blueprintable C++ function.
Set Input Mode UI only really works! Sorry for my previous comment.

Can you post a screenshot of how you implemented the OnKeyDown function, please?

First, search OnKeyDown on your blueprint EventGraph (type on key down) then right click and implement function.
Draw a line from OnKeyDown to your BlueprintCallable C++ function. Thats it.
On your C++ you can catch whatever key you want to catch.

Hi stopschildgruen,

I found a simpler way (if you only want to use C++ code).
I just found out how to override a BlueprintNativeEvent method.
We can’t use the normal method override.
For example there is a virtual OnKeyDown method in UserWidget class. If we just override the OnKeyDown, it will give error.
To override BlueprintNativeEvent methods, we need to override the Implementation method (add _Implementation to the method name)
So for OnKeyDown, we need to override OnKeyDown_Implementation method.

You can see all the methods that you can override in UserWidget header code.

Pardon me but I still can’t figure out how is this supposed to be implemented in the graph. What’s inside your “KeyDown” function? And how do you use this “OnKeyDown” function inside your graph?

Hi DynaMesh,
I’m gonna explain in a bit detail (using key_down on Blueprint Graph):

  1. Make sure that when you show the UMG UI, you set the InputMode to InputModeUIOnly from PlayerController. This means, whatever input that define in the UMG, will override the default input binding
  2. In UMG Widget Blueprint Event Graph, you can see several input-overridable functions. Choose whichever suit you.
  3. You can implement whatever you want in each input event.

. However, it will be a really long spaghetti blueprint if you choose this. I prefer, to create a blueprint callable function in C++ to be called in the blueprint like my previous post.
4. Or, you can override a UUserWidget BlueprintNativeEvent method (below).