Close UMG with key defined in Input mappings.

Hello,

I’ve search around a lot but couldn’t find a real, up to date, answer so here I am.

I’m working on my inventory / menu system. I defined a key in Project Settings → Input called “Toggle Inventory” and mapped to both spacebar and my controller start key.

I have the usual code in PlayerController to add the UMG to viewport, pause the game and switch to UI only input when the “Toggle Inventory” key is pressed:

The issue is… how do I go back ? I do know about the “KeyDown” event that can be overriden in UMGs, but you can’t use the keys defined in Project Settings → Input, you have to hard code the keys used…

I want my user to be able to customise that key later down the road, so hard coding is not an option.

A lot of old answers say to trick the system by leaving the InputMode at “Game and UI” and use the PlayerController to go back… that seems uggly.

Any up-to-date idea / tips ?

Thanks.

Yes, the idea of the other users is right… you have to use the playercontroller to get the toggle inventory event to the umg… its nasty. What might be possible is accessing the keybind information and use that knowledge to know what key press should trigger closing the umg.

A good place to start is probably looking at this code:

In UMG Widgets there is a function called ListenForInputAction:

This function will allow you to bind any predefined action, hope that helps!

EDIT:
Here is a screenshot of an example usage, just replace the Action Name with the name of your input action:

90554-umg+input.png

If you set to UIOnly, keyboard is disabled.

You have to set it in “InputAndUI” and disable input in your controller or character (I don’t remember), this way the keyboard keeps sending keys, and the character won’t move

If you use UIOnly input is disabled for actors, but the UI can still receive keyboard events! As the names suggest UIAndGame will allow actors AND UI to receive input and GameOnly will only allow actors to receive input.

Hi, thanks for that! I just look it up but I don’t really know what an “action” is in this case. It wants a string, I tried feeding it my input name, but to no avail. Do you have any experience or examples in using this ?

Thanks again. That’s what i tried but it didn’t work. Is “Fire” defined under Project settings → Input ? If yes, could it be an issue of focus on the Widget ? For completion sake, what key did you bound to Fire ?

I edited my answer and added a screenshot.

Yes Fire is an input action defined under Project Settings → Input. If it doesn’t work it might be because of the input mode, make sure you either use FInputModeGameAndUI or FInputModeUIOnly. Focus could be the issue as well, you could try to set the focus manually if the previous point didn’t make it work.

Tried it again, everything’s looking right but I can’t make it work with “UI Only”, “Game and UI” does work though. With UI only my string is never printed… Did you managed to make it worth with UIOnly ?

In my project, this is not available because keys call function on server, So I had to set it as I said … in UIOnly only mod only my mouse responds and the listen for input didn’t work even when trying consume input or not …
I don’t use add yaw input or anything else …

It seems like input components from actors and UMG widgets are handled the same way, both won’t receive input with InputModeUIOnly. So it seems like you do actually have to use GameAndUI mode for menus, the UIOnly mode seems to be really only for clicking buttons etc.

I tried many hours to do it, it would have been really easier … But it doesn’t work as shown before, for the moment you really have to use someting like the answer of this one :

https://answers.unrealengine.com/questions/119406/how-do-i-handle-action-mappings-on-an-umg-widget.html

Thanks to both of you, you confirmed what I thought. I really can’t wrap my head around why it’s so badly designed…

None of the workarounds are really working for me, as I also need to pause the game when the menu is open, and when the game is paused, no keys are sent even in GameAndUi mode…

Guess I’ll look for an hacky way now that I know the clean one won’t do it.