Help with how to handle Input correctly, it's getting really annoying

Godot Version

4.2.1 Stable

I’m getting some small bugs with the input system i implemented and i think it all stems from me not understanding the Input system well at all, i have realized through that i can use mouse_filter to ignore to skip inputs, and some other things but i cannot understand how _input should be handled in my case.
I have a player that can click to move, as well as an inventory in which items can be clicked, this works fine, however, on i indroduced the ability to hold CTRL + click to move the items quickly, the player just ignores the UI and starts walking towards where i clicked.
I tried doing it the following ways:

This is the inventory slot right now:

func _on_gui_input(event):
	# Drag, drop or identify
	if event is InputEventMouseButton and event.pressed:
		if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):

This is the player movement:

func _unhandled_input(_event):
      if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):

I have tried using Input.is_action_pressed and event.is_action_pressed as well as _Input(event) to no avail, can someone explain to me how i can make sure the UI clicks and other key presses, etc DO NOT go through and make the player move or fire a skill, i really need to understand this before adding more UI or it will be a mess.

Maybe a game state machine is useful here. You could define a number of game states (playing, menuing, etcetera) in the state machine. Then in your character controller or wherever else it is desired, you could check what the current game state is. (If the state is menuing, then the character controller knows not to react to any input.)

1 Like

This could work, however, in my game’s case i cannot do that, you should be able to use player’s inputs all the time when not hovering over menus. Its an ARPG , so it’s expected tht the player is constantly moving while doing inventory mangement, picking up loot or using skills, so i cannot afford to lock inputs.

Add line get_viewport().set_input_as_handled() to your UI code. This way it will be marked as handled and won’t propagate to your character script.
And use event.is... instead of Input.is...

2 Likes