0 votes

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?

asked Sep 12, 2018 in Engine by vspin (91 points)
edited Sep 12, 2018 by vspin

1 Answer

+1 vote
Best answer

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.

answered Sep 12, 2018 by hinasis (308 points)
selected Sep 12, 2018 by vspin

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)

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?

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.