How do you let an event be handled by the GUI and the game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By servitor
:warning: Old Version Published before Godot 3 was released.

I have created a custom control node that I am using as part of my GUI. It takes input as follows:

func _input_event(event):
if (event.type == InputEvent.MOUSE_BUTTON):
	if (event.pressed):
		print("control mouse button pressed")
		print("control mouse button released")
elif (active and event.type == InputEvent.MOUSE_MOTION):

I then have an area 2d node that is processing input as follows:

func _input(event):
if (event.type == InputEvent.MOUSE_BUTTON):
	if (event.pressed):
		print("area 2d mouse button pressed")

In this scenario, I would expect that clicking inside of the control node would produce the output “control mouse button pressed” and “control mouse button released” and then nothing else since I am accepting the event and control nodes are supposed to receive events first. Instead, I get:

 area 2d mouse button pressed
 control mouse button pressed
 control mouse button released

My understanding was that control nodes receive events first and can accept those events causing them to not be passed on to other nodes. Why is the area 2d node receiving the input event first? Am I misunderstanding this or should I be handling events a different way?

:bust_in_silhouette: Reply From: Ceilingdoor

I had the same problem when I was playing with the input methods in the engine. I had a button and an Area2D node with the _input() callback enabled. When I clicked the button, the _input() method triggered in the area node as well, although it shouldn’t have.

I tried using accept_event() but it had no effect. I solved this by using _unhandled_input() instead of _input(). This way, clicking the button didn’t triggered area’s callback for handling input and clicking outside the button activated the input method in the area.

If I want to click mouse button

and changes the property of a sprit to active visibly as phaco it?

Maiia90 | 2016-05-06 16:25

Thanks Ceilingdoor! That seems to work. Though it’s odd the desired behavior cannot be accomplished using the _input() method in conjunction with the accept_event()

servitor | 2016-05-07 03:03

Yeah, that behaviour seems strange. Basically, the input that haven’t been handled by some control is routed to _unhandled_input() and the _input() seems to catch any input that comes from the user.
accept_event() doesn’t seem to work as well as set_input_as_handled.

Ceilingdoor | 2016-05-07 05:29