How to prevent movement in _unhandled_input when clicking an object with _input_event?

Godot Version

4.6

Question

I have both Movement and Interaction on LMB. Movement is handled in _unhandled_input, and interaction is in _input_event on an Area2D.

The problem is that _unhandled_input triggers before _input_event, so the player moves whenever I try to interact. I also use the Area2D for hover highlights via mouse_entered / mouse_exited.

How can I make the object “consume” the click and prevent movement? I would like to avoid using “hacky” workarounds like manual Raycasts or point queries in _input. Is there a proper way to handle this within the standard input pipeline?

IIRC _input_event will propagate down the scene tree until the action is handled. If no node’s _input_event handles the action then _unhandled_input will propagate down the scene tree. I’m guessing that you have two actions defined in the settings, one for movement and one for interaction and they’re both mapped to LMB. I’m guessing movement propagates first and since there is no node with an _input_event that handles movement the movement event propagates all the way to _unhandled_input.

I’d recommend mapping a single action to LMB. Then when your _input_event function is called it’ll ‘consume’ the action and it won’t propagate to _unhandled_input.

use get_viewport().set_input_as_handled() to consume unhandled inputs, they will not propagate up the tree once called. Control nodes may use accept_event().