I’m sure this should be really simple, but I can’t figure out exactly how it’s done.
I have a UI I have built in a Widget Blueprint. I want to be able to make changes to it with key presses, for example pressing Space starts/stops something on the UI.
But in the Widget Blueprint itself, I can’t get a key press event. It seems one can only get those types of events inside a Player Controller Blueprint, or am I mistaken?
So I assume I need the key press to fire some kind of event in the Player Controller, which the Widget is listening for?
You need to use “Set Keyboard Focus” after “Add to Viewport”
Then go to your Widget Blueprint and override the function “On Key Down” or “On Key Up”, whatever you want.
By last, in the new function you can detect any key you want.
I really don’t know all the differences about return Handled or Unhandled, but I know that Handled block another Inputs that are in another blueprint, Unhandled not.
So I realised I hadn’t done what you’d suggested. For some reason the ‘Set Keyboard Focus’ node wasn’t showing up for me until I turned off ‘Context Sensitive’.
I can’t believe this is such an unusual thing to want to do, and yet nothing I try seems to work.
Does anyone know of a tutorial that goes through such a thing? Or does anyone have a working example of affecting a widget with the keyboard that I could look at?
this works, however you will need to use event tick for all the widget that needs input, and you need to define it for each key.
i am in the same page as you trying to enable the input for the widget, even worst since i want to swipe my widget.
There’s one piece missing here that I needed to make this work. Maybe it’s new since this was posted. In the widget, after event construct, you need to set Is Focusable to true. This allows the Set Keyboard Focus node to work. Then the key down event overrides also work.
Maybe I’m too late but the thing you need to do to make a widget get some input is to use SetInputModeUIOnly when you create your widget. So all the input events will be sent to the widget
Very very (necro tier) late, but I found a great method to make it work and I feel it’s worth sharing since it doesn’t use Event Tick.
(images included as a numbered album, since I’m a new user)
First step is allowing the Widget to be focusable, by:
Appending ‘Set Keyboard Focus’ after ‘Add To Viewport’
Image 1
Enabling ‘Is Focusable’ in Widget designer
Image 2
Next up is the override of desired function (KeyPressed/Released or any other)
Create an Event Dispatcher. Mine closes the pause menu, so I’ll call it appropriately
image 3
Drag the dispatcher onto the function and select Call.
image 4
In the function use Get Key and a set of Equals (Key) to search for keys you need. Every additional key you wish to include requires an additional pair of Equals (Key) and Branch nodes. Trues must go into the Call dispatcher, where as the final false must skip it to the Return Node. Here’s an example:
image 5
Now the final step is incorporating that into your widget’s main Event Graph.
To begin you need to bind an event there to the new dispatcher, so drag the dispatcher and choose Assign.
image 6
Plug Event Pre Construct or anything that happens before the dispatcher can be used, like so:
image 7
Lastly add any logic for what happens once the event is triggered, from the event created by Assign.