Issues with mouse click input handling

Godot Version

4.3

Question

CanvasLayer
    > Control
       > MarginContainer
           > PanelContainer
               > BoxContainer
                   > Button
                   > Label

That is my scene tree. I also have code inside _unhandled_input() to check for a "click" action and place a Sprite2D in that position. The problem is that since the CanvasLayer and the Control node both span the entire viewport, they consume the input. To overcome this, I’ve tried putting the mouse input code inside of _input() but it raises another issue where if I click on the Button the button is triggered alongside the mouse input (which places Sprite2D in mouse position) basically 1 mouse click event triggering 2 actions.

How can I fix this? Someone please help. Thank!

Many control nodes (such as Containers) have a property called Control -> Mouse -> Filter which you need to set to Ignore.

In order to determine that, you can run the game and then click on wherever you want to click. Afterwards, go to the Debugger Window and under Misc you will see which object was clicked and handled your input.

2 Likes

Thank you soo much!!! I’ve been trying to figure this out since last night.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.