Any alternative to mouse_enter for the process function perhaps?

Godot Version

Godot 4.5

Question

I have a game that depends on whether the mouse is hovering over an area (Area2D ofc) that triggers something to happen. But it doesn’t automatically detect the mouse being over it, so playing it feels like shit. Basically, this area’s detection doesn’t activate until a condition is checked like, say, pressing a button. But what if that button is where the area is? What if I want the area to automatically detect the mouse without having to flick my mouse back into so it can do what I want it to do?

Sorry if this is coming off as confusing I’m bad at describing things

But yeah, I’m wondering if I can check if the mouse is over a node in something like the process function so it can check it at all times

Area2D has a mouse_entered and mouse_exited signals you can use.

…I specifically stated that I wanted an alternative to those in something like the process function.

I know, I read your post.

There is no property that flips based on mouse entered and exited, but you can easily create your own using the signals I mentioned.

extends Area2D

var is_mouse_inside: bool

func _ready() -> void:
    mouse_entered.connect(set.bind("is_mouse_inside", true))
    mouse_exited.connect(set.bind("is_mouse_inside", false))

func _process(_delta: float) -> void:
    if is_mouse_inside:
        #do something
1 Like

No, not at all “ofc”. There are Area3Ds, and control nodes can also detect mouse events, which can be considered an area as well. Try to state what you are using exactly the first time, or at least use the edit feature.

Consider being open to improve your ability to describe things. What I said above isn’t meant to be discouraging / rude.

You should 100% take wchc’s solution, but if you are set against signals and them not being “automatic” enough, you can put get_global_mouse_position() into _process() and check if the mouse position is within the areas global position ± half the areas size.

And if the area is under a button you can try to set the buttons mouse filter property to pass.

1 Like