Quick answer: On focus loss or scene transition, call Input.action_release() on movement actions, or use Input.flush_buffered_events() to clear pending inputs.
A player holds D to move right, alt-tabs away. Game window loses focus mid-press. On return, character drifts right — get_action_strength still reports 1.0 for “move_right”.
Clear on Focus Loss
func _notification(what):
if what == NOTIFICATION_APPLICATION_FOCUS_OUT:
Input.action_release("move_left")
Input.action_release("move_right")
Input.action_release("jump")
Manually release each action. Game state resets when focus returns.
Flush All Events
Input.flush_buffered_events()
Nuclear option — clears all pending events. Use during scene transitions or pause menus.
Joystick Axis Stuck
Joystick axes won’t emit release events on disconnect. Watch for joy_connection_changed and reset on disconnect.
Input.joy_connection_changed.connect(_on_joy_change)
func _on_joy_change(device, connected):
if not connected:
Input.action_release("move_left")
Input.action_release("move_right")
Verifying
Hold direction, alt-tab. Return: character stops. Disconnect controller mid-walk: character stops. Test on each input device.
“Focus changes and device disconnects don’t auto-release. Manually clear on lifecycle events.”
For Steam Deck or handhelds, sleep mode is also focus loss — the same handler covers wake-from-sleep cleanly.