This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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?

in Engine by (91 points)
edited by

1 Answer

+3 votes
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.

by (327 points)
selected by

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:

----World (Node2D)
--------Ground (TileMap)
--------Walls (TileMap)
--------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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.