Godot Version
4.2.1
Question
I have an Area2D that is supposed to catch LMB clicks and process them. If a LMB click doesn’t land on this Area2D, another Area2D behind it is supposed to make the catch. With this in mind, I wrote the below code.
This code allows LMB events to slip through (to be spuriously caught by the element behind), about 5% of the time. But, if I move the viewport.set_input_as_handled() line so that it comes immediately after if (event is InputEventMouseButton), it works perfectly. Does anyone know why that might be? Seems like weird behavior. Thanks for any insight!
(also I know the indentation below looks a bit wrong - in my editor it is correct. Just a little trouble with formatting here)
func _on_area_2d_screwhead_input_event(viewport, event, _shape_idx):
viewport.set_input_as_handled()
if (event is InputEventMouseButton):
if !is_active:
return
if (event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT):
set_is_screwing(true)
if (event.is_released() and event.button_index == MOUSE_BUTTON_LEFT):
if !event.is_echo:
set_is_screwing(false)
...