KinematicBody2D doesn't detect mouse entering

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

There is a KinematicBody2D in my scene that is supposed to trigger a function whenever the mouse enters it. It does have a CollisionObject2D as a child and everything. Here’s the simplified code (throwing away anything that isn’t related):

export var id = ""
signal grabbed
var mouse_over = false
var moving = false

func _ready():
	$RichTextLabel.mouse_filter = RichTextLabel.MOUSE_FILTER_IGNORE
	connect("mouse_entered", self, "_on_mouse_entered")
	connect("mouse_exited", self, "_on_mouse_exited")
	connect("grabbed", get_parent(), "child_grabbed")

func _input(event):
	if Input.is_action_just_pressed("mouse_left") and mouse_over:
		emit_signal("grabbed", self)
		print("signal emitted")


func _on_mouse_entered():
	mouse_over = true
	print("mouse entered")

func _on_mouse_exited():
	mouse_over = false

The outcome is that “mouse entered” doesn’t get printed.

I probably did something stupid, but what?

:bust_in_silhouette: Reply From: kylemcclinton

KinematicBody2D inherits the “Pickable” property from CollisionObject2D, so make sure to set that to true (default for KinematicBody2D is false). In code this property is called “input_pickable”.

On a more obvious note, you could also check that your script is actually attached to the node of interest (I mention this because I don’t see an extends statement in your script).

Countless thanks! You saved the work of many people.

mymokol | 2021-03-06 08:32