4.5 UMG - how to get OnMouseButton events?

I wan’t to have global OnMouseButton Up/Down events in my widget. I’ve created new widget, implemented this event but it isn’t fired up.

Anyone know how to enable this input in widget? Maybe I misunderstand those global events in widgets.

Hello

The UMG system does not currently support mouse input. However, you could try casting from the your character blueprint to the widget. Here is an example:

18884-castinghelp2.png

I hope this helps.

Cheers

Mouse input definitely is supported - needs more documentation though! :smiley:

By default, a user widget does not handle mouse input, since normally you want things to fall through and not do extra work. The Visibility property of a user widget controls more than hidden or visible, it also controls Hit Testing. If a widget is not hit testable it will not respond to the mouse.

UserWidgets default to SelfHitTestInvisible. So the widget is not hit testable, but all children are.

In widget blueprint editor, click on [Root] in the hierarchy. There you can configure the default visibility of your user widget. If you change it to Visible, it will become hit testable and its mouse events will be called :slight_smile:

Not sure I understand what you mean by “Global”, there’s no such thing as a global handler in Slate/UMG for receiving any and all mouse events or otherwise. You only get events that your widget is privy to, based on what the user clicks on, hovers…etc, focuses…etc.

Cheers,
Nick

Thanks Nick for answer! I’m talking about those events which we can implement - those aren’t working event with Visible root.

19681-asd.png

What I’m trying to do is to create small popups that can be closed when we click outside of them, like in many games. If there will be mouse events / touch events inside widgets I would be able to do that inside a widget without moving into input from player controller.

If there is known way to do something I would like to do please let me know :slight_smile:

Hello

First off I apologize for the misleading information I gave you the first time. I misunderstood your original post. I thought you wanted the Pressed and Release events specifically. However, I may be able to assist you with a workaround for your issue. This will allow you to click “off” of a widget and close it without using the player controller. You will see why I used quotes when you read through the example.

This will require:

  1. Widget blueprint
  2. Image widget the size of the designer window (alpha set to zero)
  3. A widget you would like to close (in the example it’s a button)

You will need to drag an image widget into your designer tab and scale up so that it takes up the entire work space. You will then want to set it’s alpha to 0.0 (effectively rendering it invisible). You may also want to set it’s Zorder to 0 and the rest of the widgets to 1 or more (in this case it’s my button that’s set to 1).

You will then want to scroll to the bottom of the detail panel and change the event to an on mouse down event. You will then bind this event.

For the final step you simply have this function remove the widget from viewport.

I hope this helps.

Make it a great day

Thanks for this!

One question thou - alpha 0 means transparency on full resolution? On mobile this will slow performance a lot.

Yes it will, instead just change the Draw As to None/No Draw Type. That will actually prevent slate from generating triangles for that quad. Also, you should return Handled from that function if you’re handing the event, otherwise it will continue to bubble up through the hierarchy.

Also for your use-case, we’ve got a Menu Anchor widget coming in 4.6. More or less takes care of several of those aspects; like it spawns the popup, and dismisses it if it loses focus.