Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | scmccarthy |
I am using an Area2D with a CollisionShape2D to get mouse clicks, by connecting my handler to the _input_event signal defined by CollisionObject2D. (Yes, I have “Pickable” checked so that the Area2D can get input events.)
(Going by this reference page, this is the lowest priority thing to do with an input event and will only happen if nothing at a higher priority handled the event.)
This works perfectly well in the simplest case, but to my confusion, when I have two instances of this node overlapping each other, both of them get the mouse events. Calling “get_tree().set_input_as_handled()” in the handler does not prevent the second instance from also getting the mouse event.
For reference, here is my handler function:
func _on_Hitbox_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
held_by_cursor = true
get_tree().set_input_as_handled()
(Hitbox is the name of the Area2D node. This handler is connected to the input_event signal in the GUI.)
What am I missing? Are all applicable CollisionObject2Ds supposed to receive the event even after it’s marked as handled? Also, I thought this was done by casting a ray - shouldn’t the ray only hit one thing in the first place? I would really like to understand how this works. Finally, as a practical matter, how can I limit the click to being handled by just the topmost node that it hits (using the engine rather than rolling my own)?
Thanks for your help.