I need a way for buttons on the keyboard to make selections in UE4’s UMG widgets. Unfortunately:
A: Key press events cannot be called inside the Widget
B: Input Action events cannot be called inside the Widget
C: Custom events cannot be called inside the Widget!
D: The Widget buttons cannot be acted upon by an outside blueprint: they can send, but never receive
The only thing I can do in UMG is call events from the widget to other actors. But I cannot get a key press to select a widget. Can someone help me out here?
You can do stuff to widget buttons from outside blueprints. For example, wherever your Create Widget node is (for your overall layout widget), you can drag more wires out of the Return Value pin and get a reference to your button widgets within it, and then connect those to Set Keyboard Focus nodes. Then you would just need to create a separate Key Press Event for each Set Keyboard Focus node.
A: override OnKeyDown
B: let the controller handle those and send data to the widgets
C: yes, they can - direct reference or dispatchers
D: hook up a custom event to the same bunch of nodes as the button’s OnClicked
As @godmachine33 mentioned, you can set user / keyboard focus.
OK, I set it up with manually calling the buttons with keyboard focus, but it doesn’t seem to have any effect. Please let me know what I’m doing wrong:
A: I could try to set this up in OnKeyDown, but it’s going to require a lot of copy+pasting nodes from other functions that are currently setup for UMG’s clicking.
B: But how can the controller communicate with the widget if I can’t even get an event to call from within the widget? Widgets seem to be a one way ticket out.
C: I tried, I can send events from widgets to events in other blueprints, but I can’t receive them from inside the widget.
D: That’s what I’ve been trying to do, but I can’t receive any events in there.
There are many ways, direct communication is one of them, when you create widgets, make references and use them later to call widget’s Events from that blueprint (any blueprint):
Your first example of On Key Down does not work. What am I doing wrong? I set it up just like you have. When I view it while playing it doesn’t even show it firing.
I figured it out. I thought just creating the widget put it in focus, but apparently I have to click on it or put it in focus after its created for the On Key Down override to take any affect whats so ever.
OK, I managed to get this to work. I solved this by sending action events from the level blueprint to custom events in the UI widget. Of course there is no “click” command, so I needed both a press event and a release event. But it works without errors. Thanks!