0 votes

I have set KinematicBody2D Pickable to "On" and it has CollisionShape2D (circleshape) also. (KinematicBody2D script snip..)

func _input_event(viewport, event, shape_idx):
print(event) # never gets here..
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT:
    print("Pressed1")
    emit_signal("left_click_down", self.get_parent())

elif event is InputEventMouseButton and event.pressed == false and event.button_index == BUTTON_LEFT:
    print("Pressed2")
    emit_signal("left_click_up", self.get_parent())

I had "exactly" same way done KinematicBody (3d) and it responsed fine to mouse clicks etc. Also my node structure is similar between working 3d and not working 2d

mouse_entered signal also does not work with KinematicBody2D

Edit:
I created similarly structured test project for this and in there KinematicBody2D inputevent worked fine.. so it must be something in my code

Edit2:
From googling it looks like some other element eat events.. I have not much else than background picture and label.. (test sample did not have those) I thought events go through topmost object.. looks like no??

asked Apr 25, 2019 in Engine by Godotmus (36 points)
edited Apr 26, 2019 by Godotmus

1 Answer

+1 vote

A bit late, but you just have to check the "Pickable." box for your KinematicBody2D.
Edit: Nevermind! I misread, this is my code that is working:

if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:

For everyone else, make sure that pickable is pressed! That was what messed me up. For you the second clause should be event.is_pressed() instead of event.pressed

answered Jan 10 by Calvin Wong (16 points)
edited Jan 10 by Calvin Wong
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 How to use this Q&A? before posting your first questions.