UMG: Focus widget?

Is there a way I can focus my widget? I have a menu I bring up when Escape is pressed and I have the mouse show. Problem I am having is that the widget is not the focus. Meaning I need to click on the screen one to get the widget focus. So I am having to click twice to have my “Exit Game” button fire. Is there anyway to have it focus the widget as soon as it is opened?

There is a blueprint function that handles what has focus. "Set Input Mode Game and UI and then feed in your escape menu into as the widget to focus on.

This will give you the desired effect you are looking for. All new stuff in 4.5 to handle what has focus and so on.

2 Likes

Worked awesomely. Thank you, sir! :slight_smile:

Took me a little trial and error the first time to figure it out and get it working correctly. Glad I could help you out.

Exactly how to do it!

I just wanted to add that depending on the behavior the original post wants the SetInputMode_UIOnly node may be desired.

The SetInputMode_GameAndUI will still allow input to go to the game if you for example click outside the UI, the SetInputMode_UIOnly will not allow this to occur.

Depending on your desired behavior choose the right node, either way Toom’s explanation of how to hook it up is spot on.

Great advice!

Was this feature disabled or broken in 4.9? Because it doesn’t work in 4.9. I still have to click with a mouse on the UI before it’ll accept any Joystick input.

I’m seeing the same exact thing!

Toom’s example uses Get Owning Player Controller, which only works if your UI is situated in a HUD class.

You may want to spawn your UI from your character class (or some other blueprint). If so, you should feed in a Get Player Controller reference into the Owning Player input on the Create Widget node. This means you won’t get an Accessed None fault in the next part, which is to use Get Owning Player (gets a player controller not a player character). Now you can call Set Input Mode Game and UI from it (drag off blue output, makes the controller the Target).

This handles the problem where you run your game and haven’t yet clicked anywhere at all and the cursor still needs to be focused on the actual game standalone window (as well as the UI you want to interact with).

This was a great help. Thanks!