# How to make a collision object within a viewport detect mouse inputs?

I am working on a 2D game with a spatial node (a 3d node) inside a viewport. Nodes within the viewport should be able to detect user input from what I can find online, but for some reason it doesn't seem to work for me.

My tree holds the viewport in a viewportcontainer. The node within the viewport handles the effects of detection. In a standalone scene, the node detects mouse inputs without any problems.

The code of the spatial script:

extends Spatial

func _on_Area_input_event(camera, event, position, normal, shape_idx):
if (event is InputEventMouseButton):
print(get_parent().name)


• Handle Input Locally within the viewport is true
• Disable Input in Gui within the viewport is false
• Object Picking in the viewport is false
• The viewport container is not blocked by any other nodes

What you are doing is correct for _input. I have covered it in another answer.

Turns out that the requirement for _input_event (and the "input_event" signal) are different:

• Set gui_disable_input ("Disable Input" in "Gui") to false.
• Set physics_object_picking ("Object Picking" in "Physics") to true.

You also want to make sure that any Control that overlaps the area you are interested in has mouse_filter ("Filter" in "Mouse") set to "Ignore". Including the ViewportContainer itself. This is because Controls will take priority (even if the Control is behind what you are trying to interact with).

• I tried setting Object Picking to true. I also made sure that the node is not obscured by any other control nodes. Unfortunately, it hasn't worked Jul 29, 2022 at 8:42
• @Qusk2 To reiterate that Controls take priority, even if they are behind. And it can be the ViewportContainer itself. Which is why I'm telling you to change mouse_filter. Aug 2, 2022 at 11:14

I had a similar problem and was able to forward the input events to the viewport in an attached script like this: (The reference to the viewport may need to be adjusted)

func _input(event):
var viewport : Viewport = get_child(0)
viewport.physics_object_picking = true;
viewport.unhandled_input(event)


The script must be added to the viewport. physics_object_picking must be true. It doesn't work with _unhandled_input. The forwarding must be done in the _input function.