Problem with input spamming and _unhandled_input(event)

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


Here is my problem:

_unhandled_input(event) is executing multiple times when spamming the PRIMARY_ACTION before _order_mover_3d_to_move() returns. _detected_mover_3d.is_moving evaluates to false multiple times after the first press of PRIMARY_ACTION. Is there some kind of special execution order in Godot that is causing this? How do I prevent this?


Here is my code:

# Start Node handling the input
func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventJoypadMotion:
	if _detected_mover_3d.is_moving:
	if event.is_action_pressed(InputMappings.PRIMARY_ACTION % player_id):
		print("Primary pressed %s" % name)

func _order_mover_3d_to_move() -> void:
	print("is moving = %s" % _detected_mover_3d.is_moving)
# End Node handling the input

# Inside the _detected_mover_3d Node
var _is_moving: bool = false
var is_moving: bool: 
	get: return _is_moving

func move() -> void:
	_is_moving = true

Try checking the input in _process() instead, so you only get one input per frame.

(Also, it’s confusing having vars called “_is_moving” and “is_moving”.)

SteveSmith | 2022-12-24 12:02

I hadn’t considered polling the input. Thanks.

RudyFisher | 2022-12-24 21:04