0 votes

In a game I recently worked on, I discovered that a node with the "mouse_entered" signal doesn't make the signal run when the mouse isn't being moved, but is on the node because the camera2D is looking on the node. I hope you understand what I mean. (Kinda hard to describe)

Does anyone know how to make the signal work without the mouse moving but appearing on the node?

Godot version v3.5.1.stable.official [6fed1ffa3]
in Engine by (15 points)

The immediate thing that comes to mind is, could you write some kind of check on initiation to see it the mouse is inside the bounds of the node? Then maybe if it's true, you could manually emit the mouse_entered signal.

1 Answer

+1 vote
Best answer

You can try the following

var has_mouse_focus = false

func _ready():
    connect("mouse_entered", self, "set", ["has_mouse_focus", true])
    connect("mouse_exited", self, "set", ["has_mouse_focus", false])
by (6,870 points)
selected by

I assume you could resolve this by doing a check regarding whether the point represented by the mouse pointer is currently inside the bounds of any interesting Area2D nodes. That'd be relatively easy to do assuming you're working with rectangular areas. In that case, it shouldn't be too hard to knock up a solution generally based on a Rect2 (to represent the area of interest) and then Rect2.has_point() to check if the mouse is within it.

It's impossible to get an event when nothing happens (example not moving the mouse)

Yep, agreed in this situation. Which is why I didn't understand how the proposed solution improved the described situation.

@Retr0Cat Oh~~~~~~~~~ now understand you.
If the Area2D moves into the path of the mouse (while the mouse is not moving) it does not trigger any events. Truly odd behavior indeed

Ok so no combination of things seemed to make this right

Stumbled on a work around however since its harder to do with Node2D's added a ReferenceRect child but any control node to scale can work

extends Area2D

var has_mouse_focus = false
var click_animation = false

func _ready():
    connect("mouse_entered", self, "set", ["has_mouse_focus", true])
    connect("mouse_exited", self, "set", ["has_mouse_focus", false])

func _process(_delta):
    if has_mouse_focus and not click_animation:
    elif $ReferenceRect.get_global_rect().has_point(get_global_mouse_position()):
    elif not has_mouse_focus and not click_animation:

    if Input.is_action_just_pressed("mb_left") and has_mouse_focus and click_animation == false:
        click_animation = true

func _on_Timer_timeout():
    click_animation = false

Almost forgot about this question I asked. You're trick really helped me! Thanks a lot!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.