How to detect click on a top object only?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jackash

I know that it’s an old question, but the engine is evolving too and everything I have found on Google pretty much complicated and from 2016, maybe there are any new methods to detect only the top (rendered on top) object (Area2D with CollisionShape2D and Sprite) click?
To give a particular example: I have a TileMap which has _unhandled_input(event) which spawns a new object at some position and then I have some objects over this TileMap which have _input_event(viewport, event, shape_idx) - they also do something, but when I click on them, it also triggers the TileMap’s _unhandled_input even if I add the get_tree().set_input_as_handled() in the object’s _input_event.

So, maybe anyone knows a workaround for that?

This is not an answer to your question really but I had the same issue and couldn’t find a way around it. I am new to godot mind you. In my case, it was a text entry widget that user is allowed to type and obviously some of the alphabet keys are also mapped to actions. For eg: spacebar causing player jump even when entering text in a text box!!

I worked around it by creating a singleton that gets set when the text edit widget is on display and selected. Then player checks that before acting on keys.

Obviously inefficient way to do it. Hope someone can tell how to do it better!

sxkod | 2019-03-04 03:22