Godot Version
4.3
Question
I’m trying to make a card pop up when hovered over and return to its original position when the mouse exits the area. However, I ran into a problem: if two Control nodes overlap, the mouse_exited signal doesn’t emit when the cursor moves from one node to the other. This results in the card not returning to its original position. I’ve checked other forum posts about this issue, but still couldn’t solve it.
I found a note in the documentation that mentions a way to check if the mouse has left an area, ignoring top nodes:
Note: 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.
And I tried to use this snippet, here’s my code:
extends ColorRect
@onready var initial_position = position
func _on_mouse_entered() -> void:
for tween in get_tree().get_processed_tweens():
tween.kill()
var tween = get_tree().create_tween()
tween.tween_property(self, "position:y", initial_position.y - 30, 0.2).set_trans(Tween.TRANS_CUBIC)
func _on_mouse_exited() -> void:
for tween in get_tree().get_processed_tweens():
tween.kill()
if not Rect2(Vector2(), size).has_point(get_local_mouse_position()):
var tween = get_tree().create_tween()
tween.tween_property(self, "position:y", initial_position.y, 0.2).set_trans(Tween.TRANS_CUBIC)
The issue is that the mouse_exited
signal never emits when the mouse moves directly from one overlapping node to another. I believe there’s a simple solution to this, but I just can’t seem to figure it out. Any suggestions?