Skip to content

Today I learned

How do I test player input in Godot 4 headless, with real input actions?

#Game development

Input.action_press() lets a headless test play the game through the same actions a player uses. But a press sent at the wrong moment of the frame is never seen by is_action_just_pressed(), and the test fails at random.

The fix: wait for process_frame (it fires right before every _process), press, hold for at least one frame, release.

gdscript
func press(action: String, hold_s: float = 0.0) -> void:
    await get_tree().process_frame   # start of a frame
    Input.action_press(action)       # lands before _process
    await get_tree().process_frame
    if hold_s > 0.0:
        await get_tree().create_timer(hold_s).timeout
    Input.action_release(action)
    await get_tree().process_frame

Run it from a user argument and quit with an exit code CI can read:

bash
godot --headless --path game -- --test   # OS.get_cmdline_user_args(), then get_tree().quit(0 or 1)

If you read input in _physics_process, await physics_frame instead.

Hit this while building a two-player co-op prototype: one script walks both players through a full scenario in about 80 seconds.

Docs: Input.action_press

The 30-second version

Share LinkedIn Post on X

Related notes

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.