Download

UMG Mouse input on 2 different Widgets

Hey, so I wana have Widget A and Widget B, both added to viewport. Input Mode is supposes to be UI and game, so if no Widget is clicked, the game receives the input. By changing the Z-Order, I can choose which of the 2 widgets receive the Input when I click on one of them. But I want both to be able to Receive Input.

What is happening: Widget A is on the left side of my screen, Widget B on the right. The Widget with the higher Z order will receive input, while the click goes right trough the Buttons of the other Widget.

Desired behavior: Widget A and B both can be clicked, and if the mouse clicks on neither of them, game receives the input.

Any idea how I can fix/ achieve this?

You can control this behaviour by returning Handled / Unhandled replies when overriding mouse events:

  • Handled - the input is consumed and neither the widget underneath or the game will be notified
  • Unhandled - the input is not consumed and will tunnel to the elements underneath, if no other widget Handles it, the input will eventually arrive at the Player Controller a.k.a. the Game (unless we’re in the UI-only input mode, of course)

In addition, I’m intercepting the clicks here, giving this widget a chance to act accordingly, depending on which button was clicked.

In this very case:

  • LMB will call the Clicked event and terminate (handled)
  • RMB will call the Clicked event and carry on, looking for another input recipient (unhandled)
  • other mouse buttons will not call the event and also carry on (unhandled); you could middle-mouse click on a Visible widget and still have the player controller rotate the camera, for example

One note, it gets somewhat tricky with Buttons as they very hungrily consume input. Essentially, if a click lands on a button, the UMG will think you really meant it and just eat it. There’s a feature called Precise Click but I don’t think that’s what you’re after here. Or is it specifically for buttons?

After dealing with UMG for years now, i’m really against using buttons for anything other than simple click & forget or debug. Totally biased.


Widget overrides sit here:

Thanks for your great answer! Overriding the mouse handle didn’t change things in my specific case, but I found the culprint now…

I had a Set Visibillity node, which set the Widget to Visible. (Which apparently doesn’t consume the Input for the Game, just makes it invisible for any other Widget). For the described desired result it has to be Not_Hit_Testable.

1 Like

Glad to hear that.

Desired behavior: Widget A and B both can be clicked

I was posting under the impression that the above was the requirement. Setting a widget to Not_Hit_Testable will prevent it from being clickable.

There are 2 options here, Self Only and Self & All Children Not Hit-Testable. They behave differently.

Self only is the only option that makes sense for the described case, yes.

Was my bad to overlook the node, I think I purposely set it to visible back in the day to avoid Drag and Drop conflicts.