Prevent background touch events on ui interaction

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Daniel Mircea
:warning: Old Version Published before Godot 3 was released.

I’m working on a mobile game. I’m having a hard time telling apart taps from touch screen buttons from regular ones from the remaining screen.

Is there a way to prevent event propagation for touch events for filter them somehow?

I tried setting a custom action name on the TouchScreenButton nodes and tried to filter them with event.is_action to no avail.

:bust_in_silhouette: Reply From: brunosxs

I’d go the easy route, creating two different states, deactivating the game logic while the ui is on… or at least deactivating key objects that could get in the way.

This won’t work because the ui is always visible.

Daniel Mircea | 2017-11-18 10:52

:bust_in_silhouette: Reply From: MrMonk

You can set input event as “handled” so it doesn’t trigger anything else by calling

SceneTree.set_input_as_handled()

but it seems that is not working well on android… I disable input on other nodes when I detect a touch on UI.

I opened this issue on github. Would help if people interested wold support me there so we can have this solved.
[2.1.4] Input not handled by GUI on Android · Issue #13256 · godotengine/godot · GitHub

MrMonk | 2017-11-25 07:06

This PR is going to fix the problem:
Stop GUI touch event propagation by FuzzyRhombus · Pull Request #11305 · godotengine/godot · GitHub
I just did the testing, works as advertised… But it took me more than two hours to figure out the Android template compiling … But now it works, if someone want to try the android_template, maybe I will post it for dl somewhere…

MrMonk | 2017-11-25 11:52