UMG Key Pressed

Hi all, i have a UMG menu and i want to close it when the user press the “p” key, but in the UMG there is no “p key pressed” event. How i can do that?

Another question: why,when i open the menu, i have to click twice for run the click event on the button? It’s looks like that the umg has no focus.

To close a widget you have to remove it from the viewport (with the node called “Remove from Parent”.

Just save the return value from “Create Widget” in a variable and use that to remove it when you press your key.

And for the focus. There are events to bring a widget into focus. Like “Set Focus UI” (something close to that. It’s not quite the exact name). For this you will need again the widget reference.

Just add a Event for it in your Character, Level or Hud BP.

Ok, i resolved the focus problem with “SetInputMode_UIOnly” node. Now the problem is : How to detect that the player pressed the “P” key in the UMG?

I already have an event for the key and i can call it in the Level blueprint, but i can’t call it during UMG blueprint. How to access to that event?

You don’t need to. For text you can set the keyboard focus to UMG but if you want to remove it use “Remove from Parent”.

yes, i need it, because i want that the player could open the menu pressing the “p” key and that he could close it pressing again the “p” key but i don’t know how to manage the “p pressed” on the UMG blueprint

I can’t do like that because when i call the Widget in the level blueprint the game stop read “level blueprint” and start reading the “umg blueprint”, so if i control that the user pressed again the p in the level blueprint the game will do nothing, that’s my problem :\

Does the “Set Input Mode Game and UI” allow the “p” event to fire?
It says that the if the input doesn’t get handled by the widget then the Controller gets a chance to

Does the “Set Tickable when Paused” allow the level blueprint to keep running?

What do you mean by “Ok i found how to control if the user press the p key during UMG”?

The real problem was that when i create the UMG i put the “pause game” node, and it blocked the level blueprint script. Now i can close the menu with “p key” but how to stop the game run when the umg is open?

Ok i found how to control if the user press the p key during UMG, i need an event that could control that script, like “when a key is pressed” or something like that. Any suggestion how to do that?

Using that nodes i can control when the user press the “p key” in the umg, but i can’t use event tick because it fires always, so when i press the “p key” for the first time the game open the menu ( i can see it) but the game close it at the same moment. So i need another event, but i can’t find a solution

If you use the flip flop node then each time the “p” key is pressed it will do the opposite of what it did last time

So the first time I press “p” it will print “Open” and the next time it will print “Close” then open then close etc…

Just make sure you only handle input with the “Was Input Key Just Pressed” node

May I ask you to listen to me?

From what I could gather you use the level blueprint for your logic. Not ideal but here’s a solution exactly as I described it.

The variable widget is simply of the type “Widget”. Please also notice that the checkbox “Execute when paused” inside of the “Event P” is enabled. First you create the widget, save it in a variable and then toggle between adding it to the view port and removing it from the same. A FlipFlop simply switches between A and B every time it’s called.

I hope this clears things up.

Cheers.

Yes this ^^

I did not know that you could set inputs to be executed when paused Thanks!!

Man, thank you. That’s work fine! Just a little bug but i can resolve it, never noticed about the “execute when paused”! Thank you, sir!

How does this thing work in 4.9? I spend 6 hours trying allmost everything possible yet I still can’t close my pause menu by keyboard.

Pause menu?

Are you using the Unreal function to pause / freeze the game? Because if you do your input events to the controller will be frozen as well unless specified otherwise in the variable defaults.