0 votes

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?

Godot version 3.2.3
in Engine by (92 points)

1 Answer

+1 vote
Best answer

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).

by (154 points)
selected by

Countless thanks! You saved the work of many people.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.