Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | NicTrib |
I am trying to detect when the mouse is over the HUD UI, so that other objects don’t do anything when the user clicks on the UI.
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | NicTrib |
I am trying to detect when the mouse is over the HUD UI, so that other objects don’t do anything when the user clicks on the UI.
Reply From: | ProXFox |
there’s a signal for all control (UI) nodes that says “mouse_entered()”. use it.
Reply From: | VastView |
I’ve also been struggling with this! I found that the only way is by checking for each indiviual UI element, or by seeing if the mouse is inside the area of a panel, e.g. an inventory panel.
Here’s the current documentation:
● mouse_entered()Emitted when the mouse enters the control's Rect area, provided its mouse_filter lets the event reach it.
Note: mouse_entered will not be emitted if the mouse enters a child Control node before entering the parent's Rect area, at least until the mouse is moved to reach the parent's Rect area.
● mouse_exited()Emitted when the mouse leaves the control's Rect area, provided its mouse_filter lets the event reach it.
Note: mouse_exited will be emitted if the mouse enters a child Control node, even if the mouse cursor is still inside the parent's Rect area.
If you want to check whether the mouse truly left the area, ignoring any top nodes, you can use code like this:
func _on_mouse_exited():
if not Rect2(Vector2(), size).has_point(get_local_mouse_position()):
# Not hovering over area.
Hope this helps!
Kind regards,
VastView
For anybody new who is looking for solution:
I had the same problem and using mouse_entered
for every control node didn’t seem right.
I found out that if you handle input in the _unhandled_input
function instead of _input
, it will trigger only if the mouse is not hovering over UI.
So, for objects that you don’t want to react to mouse input (while user is hovering over the UI), use _unhandled_input
instead.