How to prevent World input events from firing when overlay controls are clicked?

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

My game world (TileMap) captures input events, specifically mouse down/up. My controls are overlayed on top of my game world. How do I prevent events from firing on my game world when my overlayed controls are clicked?

Unity has a ray cast target flag for UI elements. Is there something similar?

:bust_in_silhouette: Reply From: hinasis

Select the base Control node of your overlayed control, say Container,Control or whatever it is. Set its Mouse → Filter parameter to “Stop”, so input will stop propagating when it reachs its layer. Or you can just set each button to stop if there are no tangible/palpable parent container.
It’s a magic parameter, “ignore” will ignore all inputs, “pass” will get the input event but keeps propagating, “stop” will get the input event and set it as handled stoping its propagation.
Children of control can have different mouse filters, for example, a big Container holding a small Button has stop filter, but the button has pass, so you can click the button but it prevents clicking whatever is under the container.

I tried all those settings, and still, the InputEventMouseButton and InputEventMouseMotion fire on my World script. Maybe I’m doing something wrong? My hierarchy looks like this:

-root
----World (Node2D)
--------Ground (TileMap)
--------Walls (TileMap)
--------Camera2D
----CanvasLayer
--------Control <—|
------------Button ← (no matter what i set, Input Events fire on the World script on click)

vspin | 2018-09-12 10:17

So, there is a problem in the way you get the input. It’s a common fault, because it’s not as clear as needed.
How do you check for it?

hinasis | 2018-09-12 13:37

Ugh! You’re correct. I was using the _input function, and replaced it with _unhandled_input which now works as you described.

vspin | 2018-09-12 19:02