Godot Version
Godot version 4.3
Question
`I’m working on a mobile game where the player jumps when tapping the screen. However, tapping UI elements (e.g., Buttons, PopupMenus) still triggers Jump(), even when I try to detect UI interactions.
Current _input() Function:
func _input(event):
if global.control_mode == "tilt":
if event is InputEventScreenTouch and event.pressed:
if is_ui_under_touch(event):
get_viewport().gui_accept_event() # Consume the event
return
Jump()
What I’ve Tried So Far:
-
Checking if UI is under touch with is_ui_under_touch(event), using get_global_rect().has_point(event.position).
-
Calling gui_accept_event() to consume the event before it reaches gameplay logic.
Using _unhandled_input(event) instead of _input(event) (but it didn’t stop the issue). -
Ensuring UI elements are inside a CanvasLayer and part of the “ui” group for proper detection.
-
Testing if gui_get_focus_owner() detects UI interactions.
Despite all this, UI elements still allow touch events to pass through and trigger Jump().
Since I’m really new to Godot, this could well be an issue with my scene or project structure. Any guidance on how to properly block gameplay input when interacting with UI would be much appreciated! `