Nodes in viewport consume clicks that were made outside the viewport

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

In my game, there’s a viewport that has, as a child, a world.
The viewport takes half the screen space, and on the other half there are buttons that are not children of the viewport.
However, when clicking on those buttons, the input is consumed by nodes that are in the viewport world (and of course are not visible right now through the viewport - since the click was outside the viewport) instead of the buttons that are outside the viewport.

The viewport itself was not clicked on, but the world inside it consumed the input. Is that a bug?

:bust_in_silhouette: Reply From: Inces

Every node consume input event, if you want the node to only consume input when mouse cursor is in its borders, then You have to specify such conditions. Buttons and some control nodes use on pressed signal, so You don’t have to do this with them.

Thanks. Isn’t it part of the viewport’s functionality, to filter out inputs that take place outside its borders (that is, outside the world that it presents) ? It makes sense to me that it should be.

avnih | 2021-03-23 12:19

I don’t know about that.
However input is filtrated in some degree, check unhandled-input in documentation, this is propably what You are looking for

Inces | 2021-03-23 16:07

:bust_in_silhouette: Reply From: avnih

It seems like setting viewport’s handle_input_locally property might be the solution.

Sorry, I was wrong, This property doesn’t solve the issue.

avnih | 2021-04-16 15:28

:bust_in_silhouette: Reply From: avnih

I ended up adding this script to the enclosing ViewportContainer:

func _input(ev):
	if ev is InputEventMouseButton:
		$Viewport.gui_disable_input = false
		if ev.position.x<rect_position.x or ev.position.y<rect_position.y or ev.position.x>(rect_position.x+rect_size.x) or ev.position.y>(rect_position.y+rect_size.y):
			$Viewport.gui_disable_input = true