How to check if mouse is over any widget

Hi,

How can I check if my mouse is over any input consuming widget such as button in CPP or Blueprint? Is there any method where we can poll the HUD to test against Visible widgets?
I’m doing a trace and it executes even when I’m over UI pieces and I’d like to make sure the trace does not execute while hovering any widget.

Best Regards!

Buttons have an event for it.

Scroll down on the Details panel (right side) and you’ll find…

120350-button_details.jpg

OnHover
and
OnUnhover


You can use a boolean to test if the mouse is remaining hovered.

120361-button_mouse.jpg

1 Like

Hi Looniper,

Thank you for your answer :smiley: That would work for a single button but now presume I have images, borders, and whatever else in the screen at the same time and I still want to be know if my mouse is over a widget or not, how would I go about that?
I can’t exactly add 50 “OnHovered” and “OnUnhovered” and most of these widgets don’t even have this event :frowning:

Thank you for your help!

Ah, sorry, you had mentioned buttons so I just assumed it was a specific element you wanted to watch.

You want Borders.
You can place as many other elements as you like on them, and adjust their transparency to make the border itself hidden(leave it visible, just set the alpha to 0)

It has an OnMouseMove event that only takes place when the mouse moves over the border itself.

By placing a larger border (Exit) around the one containing the elements you want ‘blocked’ (Enter) - you can turn the boolean showing that the mouse is over that area on and off.

In this case I used Green for the “Enter” border and Red for the “Exit”
(the little red button was to ensure it worked, which it did)

.

Then just bind the OnMouseMove for each to set the boolean.

120380-boder_flag.jpg

Just to add to this answer, rather than using “DummyReply” you can drag off the return pin and put a “Handled” instead, Save a variable :slight_smile:

Thank you so much! I didn’t know you could do that! It saved my project!

This is an old question, I know, but worth pointing out for anyone that needs it, that widgets now have IsHovered pure blueprint that returns True when hovered.

8 Likes

Not working when press right mouse button. Hover event canceled.
Why?

If you use “Delay until next tick” - node, that should fix your issue.