Need help with GUI Mouse Filtering

Godot Version

4.7.2

Question

I have an issue while trying to make a simple popup system. The goal is to close the popup if anywhere on the screen is clicked besides the visual popup itself.

I tried doing that my making the parent control take up the whole space and set it to Mouse → Filter → Pass and the visual container itself to stop the mouse inputs.


And I have a little script in the root of this scene that connects to the gui_input signal to try and catch that input outside of the visual popup.

func _on_gui_input(event: InputEvent) -> void:
	print(event)
	if Input.is_action_just_pressed("lmb_click"):
		if self.visible:
			self.visible = false

But with this setup, I basically get nothing. I don’t get anything printed out if I have the popup open, the only real thing happening is the visuals of the popup actually stopping the mouse input, but anything outside of it gets picked up by other GUI but doesn’t trigger gui_input. I also tried to do it via the _gui_input() function but it yielded the same results.

I am not sure what is causing this behavior or if I am misunderstanding how this should work, I have a vague feeling about this being related to Behavior Recursive option but playing around it didn’t yield much results, and I didn’t fully understand it from reading the docs.

(post deleted by author)

I noticed that your root Control has a z-index of 2. The input system uses the SceneTree hierarchy not the rendered one.

Don’t use Input inside any of the input callbacks. Use InputEvent.is_action_pressed() instead and similar methods.

Yeah I am aware that is uses the SceneTree hierarchy, but by those standards it should still work I believe. The visual part is below in hierarchy than the full scale control.

I am not sure what you exactly meant by don’t use Input sorry. You mean that instead of Input.is_action_just_pressed I should use InputEvent.is_action_just_pressed or even event.is_action_just_pressed ?

But either way the issue is still that the gui_input doesn’t fire at all