Using Keyboard Control in a Widget

I am trying to setup a system that I can use to push a button in game and open a menu or something and then push the same button to close the widget that was opened.

I will post a setup of how to do this when I get home, you basically want to create the widget in UMG. Then from your character you want to say, when you press x key split to a switch node, the first point will create the widget and then add it to viewport, the second point will drag off and remove the widget from the viewport.

This link may also be useful: Creating Widgets | Unreal Engine Documentation

Ok, this is how I have done it. Not sure if it is the correct way, but this way will remove all widgets from your viewport.

Character Blueprint: Screenshot - 2a23c2794831f2817a0ddffe958b5b6c - Gyazo

We are basically saying, when we press the “M” key, open the main menu widget, add it to the viewport and show the mouse cursor, when we press the “M” key for a second time, we simply remove all widgets from the screen and hide the mouse cursor.

Hope this helps!

This is exactly what I was looking for… Thank you so much.

I have tried this several times over now and it isn’t working with 4.10.2. my character blueprint is setup just like yours is but I can’t close the pause menu once I open it. I hit it once it opens the pause menu. I hit it a second time nothing happens. I hit resume on my pause menu to go back to game and then hit the Pause button again and ALL widgets are pulled off even the one for my user interface lol. I am getting stumped here and about to just leave it how I had it for now.

First, remove that from your Character Blueprint and move it to your PlayerController blueprint. Reason: if you aren’t possessing your character you won’t be able to bring up the widget.

Don’t use a FlipFlop for something where it is possible to bypass the flipflop (Pressing Resume instead of going to FlipFlop B).

There’s 3 input modes for widgets: Game, Game and UI, and UI. In my case I use Game and UI because the character can still move with the menu up

ok I will give that a try thank you

Ok I gave this a try and it gives me an error about the remove parent being null when I press my P button again for my pause menu. This is getting rather annoying and you would think it would be fairly simple to understand.

Ignore previous post… I forgot the creation of a new boolean is set to true by default upon compiling

actually still have a problem… argh lol… when I press my P button it opens the pause menu but when I press the P button again it STILL doesn’t close the pause menu I have to hit resume game to clear it off.
Once I have cleared it off I then have to hit the P button twice to bring up the Pause Menu because it has to go through the true part of that branch before it can do the false part again.

***** Update *****
Long as I make the input mode that is being set to Game mode AND UI it will work. Guess I will have to use a paused Game in there because I don’t want the character to be able to move and all.

****** Update *****

Nope that isn’t working either… ARGH

Override the OnKeyDown function in your widget Event Graph.

I put this in the main of the widget I am wanting to give key control to right?

I don’t have an on key down function in my widget… am I missing something here cause I have never seen this function before

NVM UI found it

New problem has accord. When I alt tab out and back in the control of the game has been lost until I click on it… Is there a way to prevent this issue when alt tabbing in and out of games?