Mouse enter/ exit signal are donked

Godot Version

v4.3.stable

Question

so I have this weird problem, when hovering over this control node, if i move the cursor to the left, hovering over the node, the mouse enter and exit signals work normally but when i move my cursor over the node but in the right direction, the mouse enter and exit signals start firing at every pixel basically that I move the mouse, but its all fine again if i just move the cursor in the left direction. below is code from the script which is attached to the aforementioned control node, thanks in advance

extends Panel

var item_info_card_scene = preload("res://scenes/menus/item_info_card.tscn")
var item = null
var item_card = null


func _ready():
	connect("mouse_entered", _on_mouse_enter)
	connect("mouse_exited", _on_mouse_exit)

func handle_item_info_card(item):
	if item:
		item_card = item_info_card_scene.instantiate()
		item_card.global_position = get_global_mouse_position()
		add_child(item_card)
	else:
		if item_card:
			item_card.queue_free()
			item_card = null

func _input(event: InputEvent) -> void:
	if item_card:
		item_card.global_position = get_global_mouse_position()

func _on_mouse_enter():
	print("mouse in")
	if slot_type != SlotType.HOTBAR:
		if item:
			handle_item_info_card(item)

func _on_mouse_exit():
	print("mouse out")
	if slot_type != SlotType.HOTBAR:
		if item:
			handle_item_info_card(null)

PS, it started happening, or at least became noticeable, when I added the logic for the item info card, which is why I decided to include it in the code snippet

When you add the item_info_card_scene, it’s positioned to the right of the mouse cursor, so when you move the mouse to the right, it goes on top of the newly added scene and mouse_exited is emitted. You can fix this by changing the mouse_filter property in the item_info_card_scene to ignore. This way the scene on top won’t block the cursor.

2 Likes

This is what was happening. I didn’t consider that there might be a delay with the position setting.