binding umg buttons to input keys

This is probably a dumb question but how do you go about binding a umg button to lets say the 1 key? been trying to figure this out for a few hours not and cant seem to figure it out. MY buttons are set up for a hotbar (or action bar which ever you prefer) the button it self gets called from another widget but i have all the hot bars assigned to a specific slot so that the slot number can get called from any blueprint if needed. but i cant seem to get it to acknowledge that the button was pressed.

Set Inputmode to the widget wich should grab the key add key event to to widgets graph and well do as you would normaly do :smiley:

im not understanding the key event any chance you can elaborate a bit. cause the way im working it is that that from the spell blueprint it will find which slot number its in on the hot bar and as long as that icon is in the slot thats pressed it will cast its spell but i cant seem to set up the number inputs from the keyboard . and i cant find anything that will key bind a button. so if you could elaborate that would be great.

thanks :smiley:

I asked a similar question : UMG - Keyboard shortcuts - UI - Epic Developer Community Forums

It seems there isn’t a “native” way to do it yet, umg with keyboard and pad isn’t as good as it is with the mouse yet.

ill try those out thanks wish they just had it setup to enable keybinding

We’re still working on controller input and general input improvements to UMG. You always have the ability to override the incoming keys from slate via the overridable functions on the widget. But those require that focus is on your widget. That is to say, your hot bar would require that it or a child widget has focus. That’s the way real UI systems work for better or worse. While it may sound like a hassle for a small simple UI, it’s incredibly important if you’re building a very complicated UI system.

So - what do you do?

The answer is to not have input bound to UI. Instead the input binding should be performed by the standard input binding system, the same way you would bind jump or move forward. You don’t bind 1 to the button you bind it to PerformSlot1Action. The underlying game code then maps that binding to some UObject’s function/event in a blueprint of the pawn/character…etc and executes the right action. The UI similarly would ask the pawn/character to perform whatever the action is for the ActionSlot it’s mapped to when clicked. Think of Buttons and other UI elements as just another game pad that can send commands.

I asked the same question and after several days I came to a conclusion that it’s not possible, in how you wanted it anyway. Actually, I think this is a very major problem because I wanted a button control for my flight mobile game but I couldn’t do it. With virtual joystick awful gameplay, I changed the whole project as a PC/Console project and targeted to Steam Greenlight now. But I really, really…“really” wanted to make a mobile game with the great control manouverability of the PC controls. I wish UMG gets the data directly from input -which gets it’s data from whatever blueprint it represents.

So my hope in near future (I hope anyway, not too far :slight_smile: ) UMG will support direct On-Bind events from input buttons.

well after doing everything i can think of i found out that i can change the number of the slot no problem but only viewed as a print string. which means there is no communication at all to the child widgets. which in turn means we cant set them at all unless has an example to show us . i spent the past few hours just trying to change the value of the number i have set up thats connected to my slot widget . but that number wont change no matter what i do. so now im at a loss. if you got an example for this it would be really appreciated cause i cant figure it out.

thanks :smiley:

i second this. being able to pull the input event from the character is a must for UMG.

I third this.

ive been faking it by changing the opacity of the images depending on character ability cooldowns. then i can just bind keyboard events to the same custom event s that are fired by the buttons. [video]https://www…com/s/hwxjbk5hbl5u449/2015-03-23-2002-26.flv?dl=0[/video]

I remember in UE4.6 I felt screwed and just plain gave up and went mouse only. Attempting to have the normal input system communicate with the widget was crashing the engine so badly I couldn’t even open my project without deleting the widget first. I haven’t tried it in UE4.7 yet. It sounds like it might work without crashing this time, but You really need a native input system for UMG. Doesn’t even seem like it would be that hard.

Hello invayne,

I believe I have a answer that may be viable to the original question of how to setup OnKeyDown/OnkeyUp events inside of widgets. I hope this helps.

You will need to use the OnKeyDown/OnkeyUp override function that can be found in the MyBlueprint panel.

KeyboardInputHelp3.png

Here is an example of an OnKeyDown function. This function checks to see if the key pressed is the ‘1’ key. If it is it will print out a line saying something to the effect of “That is the 1 key alright!” and if not it will say “That’s the wrong key”. Please not that you may want to include a not equal to node that will return the keyboard focus to normal. I have done this with the escape key in this example.

The keyboard focus needs to be set for the widget you would like to use the keyboard inputs for, otherwise it will not be looking for them. NOTE: as long as the keyboard focus in on the widget it will consume all keyboard inputs. This is why you would need some way to “UNset” the focus. In the case of these examples you will see that I set the input mode to game and UI in the above picture.

KeyboardInputHelp3.png

Make it a great day

1 Like

Looks like a pretty good solution, especially paired with 's rebindable key functions. Thanks, Rudy!

It doesn’t look pretty, but it works! I’m so glad because this has been bugging me for a while. I used a macro because it was originally going to branch, but then I decided to have it not only test the key, but take action as well. Thank God my menu will never have more than 6 options! It would get even uglier.

I did a shortcut key feature using the answer I gave on this question

https://answers.unrealengine.com/questions/142832/umg-keyboard-shortcuts.html

I’m curious Rudy, is there a way to get this to work with an Action Mapping rather than a specific key? That way we could get it to be more multi-input friendly. In my case I’m using this setup to close the widget (menu) with the same key you use to open it (esc) but if I could use an action mapping, then it would work with the gamepad.

Right now my approach is to bounce the inputs off the controller through event dispatchers(My top level widget hooks into controller dispatches to receive notification of different actions). I feel like maybe I’m doing this a crazy way. Maybe.

I find excellent soluiton.Thanks to Mathew Wadstein WTF Is? Enable / Disable Input in Unreal Engine 4 ( UE4 ) - YouTube