How can I get around godot's mouse filter bug?

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

I have a button that needs to fire when pressed but still pass on the input event. The pass event is working like the stop event so it does not work. How can I get around that?

Pass means that event propagation goes to parent node.
what node tries to catch the input event? is it parent or ancestor node of the Button node?

volzhs | 2019-10-03 12:28

A ancestor node is trying to receive the event. I thought pass is supposed to fire the event but it continues to propagate up the scene tree until consumed.

jujumumu | 2019-10-03 23:39

Setting the flag toIgnore worked for me. I usually run into trouble with this when I have nested containers, as the children get by default set to Pass. It can take a bit to figure out that you just forgot to let the container ignore mouse events all together.

MiquelRamirez | 2020-05-13 12:56

:bust_in_silhouette: Reply From: navi2000

I had a similar problem, I think it’s a bug or maybe I’m not understanding how it works.

In a scene like this:

-Node2D
|- …
|- …
|- CanvasLayer
|- Container (any type, I have tested all)
|- Button

I have tried all combinations of stop/pass/ignore and _input, _unhandled_input, etc. without success.

At the end the only solution I’ve found is forget the on_pressed signal and and this code to my button:

extends Button

var _hover = false


func _ready():
	connect("mouse_entered", self, "_on_accept_mouse_entered")
	connect("mouse_exited", self, "_on_accept_mouse_exited")

func _input(event):
	if _hover and event is InputEventMouseButton:
		accept_event()
		if event.pressed:
			_pressed()


func _pressed():
	_hover = false
	do_whatever_you_need_to_do_with_your_button_on_pressed()


func _on_accept_mouse_entered():
	_hover = true


func _on_accept_mouse_exited():
	_hover = false

Sorry, can’t edit: the Container is a child of CanvasLayer and Button is a child of Container.

navi2000 | 2020-04-13 13:08