defold / defold/defold

on_input called once per frame while key is held

Open
#8,895 6 comments 0 reactions 0 assignees View on GitHub
bug engine
Dominant language
C++
Stars
6.3k
Forks
455
Avg merge
1d 19h
Merged PRs (30d)
130

Description

**Describe the bug (REQUIRED)**

`on_input` is called every frame while a bound key is held, but it should only be called when the key is pressed, repeated, or released.

**To Reproduce (REQUIRED)**

1. Create an empty project
2. add one key to the input binding and remove the mouse binding
3. add a single game object
4. create and add a script to the game object
5. paste this code into the script
```
function init(self)
msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action)
print(action_id, "pressed:", action.pressed, "released:", action.released)
end
```
6. Run the app
7. press and hold the bound key
8. Look at the console output to see bug being demonstrated

**Expected behavior (REQUIRED)**

You should see just one line of output in the console:
`DEBUG:SCRIPT: hash: [my_action] pressed: true released: false`

**Actual behavior**

You see the expected line in the console, then another line getting repeated every frame:
`DEBUG:SCRIPT: hash: [my_action] pressed: true released: false`
`[n++] DEBUG:SCRIPT: hash: [my_action] pressed: false released: false`

**Defold version (REQUIRED):**
- 1.8.0

**Platforms (REQUIRED):**
- macOS Sonoma 14.4.1
- Mac

**Minimal repro case project (OPTIONAL):**
[input_bug.zip](https://github.com/defold/defold/files/15243772/input_bug.zip)

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied minimal reproduction and tracing the on_input entry point after acquire_input_focus, using the key binding and script shown in the issue. Done means a held key produces only the press, repeat, or release callbacks described by the expected behavior, rather than a callback on every frame.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, lua
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.