Why is my mouse_enter signal not working?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Michiel Papenhove

See the code below. I am wondering why the mouse_enter signal doesn’t get triggered. Can anybody help me out?

extends Node2D

var startMenuItems = {
	"item1": "new",
	"item2": "load",
	"item3": "options",
	"item4": "exit"
}

func _create_menu_items():
	var fnt = load("res://fonts/Magegamefont2_smaller.tres")
	var y = 0
	for item in startMenuItems:
		var label = Label.new()
		label.set("text", item)
		label.set("rect_position", Vector2(0,y))
		label.set("custom_fonts/font", fnt)
		connect("mouse_enter", label, "_on_mouse_over")
		label.set("mouse_filter", Control.MOUSE_FILTER_STOP)
		self.add_child(label)
		y += 30
		
func _on_mouse_over(event):
	print("mouse over")

func _ready():
	_create_menu_items()
	pass
:bust_in_silhouette: Reply From: njamster

You’re connecting the (non-existent) signal “mouse_enter” of your Node2D to a (non-existent) callback-function _on_mouse_over on your label.

What you most likely want to do is this:

    label.connect("mouse_entered", self, "_on_mouse_over")

Ah, that’s it :slight_smile: Thanks a lot!

Michiel Papenhove | 2020-04-11 17:09