Describe the project you are working on:
Projects with Input events and Input maps
Describe the problem or limitation you are having in your project:
I was not aware about the fact that Input.is_action_just_pressed("action") could be called multiple times per frame, but thanks to this post on reddit I was made aware.
Describe how this feature / enhancement will help you overcome this problem or limitation:
A yellow warning would be nice to tell me about the risk and the recommended alternative.
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
something like:
"Using Input.is_action ... calls in _input(event) might get called more than once per frame. Use event.is_action('my_action') instead"
Describe implementation detail for your proposal (in code), if possible:
not possible
If this enhancement will not be used often, can it be worked around with a few lines of script?:
used often by those not aware
Is there a reason why this should be core and not an add-on in the asset library?:
to help people not to create unnecessary bugs
Not related to the issue, but is there an alternative besides using event.is_action? I've had buggy behavior using that (events stop being sent after 1 second, making it impossible to tell if an action is held or not). Is Input meant to be used in _physics_process instead, or can it be called multiple times there, too?
@regakakobigman To my understanding, you should be able to tell if an input is held or not based on whether the event.is_echo() method returns true or false.
I use Input.is_action_pressed("my_action") in _input(event): if event.is_class("InputEventMouseMotion"), to check if a key is pressed, while moving the mouse.
This check is done once per InputEventMouseMotion-event, which is, as desired, multiple times per frame.
Using Input.is_action... in _input(event) is not necessarily inefficient or a bug.
If the event is not a key-event, it's convenient.
Although:
If event is a key-event (keyboard, mouse-key, joystick-key, etc.), event.is_action_pressed("my_action") or event.is_action_released("my_action") should be used instead of Input.is_action_just_pressed("my_action") or Input.is_action_just_released("my_action").
Input.is_action...() queries an action, while event.is_action...() uses a value already passed to _input(), which is faster.
Please note:
Although the word "just" is missing, event.is_action_...() corresponds to Input.is_action_just...().
This is exactly why I would not recommend _input(event) for beginners unless they are able to and want to read the source code about what is going on.
I can't read the source code to understand what's going on and the docs are not helping either. Which is why even though I'm using Godot now for a year and a halve, I still much rather use Input.is_action ... in the process loop.
Please note:
Although the word "just" is missing, event.is_action_...() corresponds to Input.is_action_just...().
Really? That's terribly misleading.
Please note: Although the word "just" is missing, event.is_action_...() corresponds to Input.is_action_just...().Really? That's terribly misleading.
It's something to keep in mind.
event.is_action_... is only triggered if the state of a button or key changes, while Input.is_action_... queries the current state of the button / key.
If you want to know if two buttons have been pressed at the same time, Input.is_action_just_... is the way to go. (e.g. for combos in a fighting game)
If you want to know if a button is pressed, no matter when it has been pressed, Input.is_action_... is the way.
Most helpful comment
I use
Input.is_action_pressed("my_action")in_input(event):ifevent.is_class("InputEventMouseMotion"), to check if a key is pressed, while moving the mouse.This check is done once per InputEventMouseMotion-event, which is, as desired, multiple times per frame.
Using
Input.is_action...in_input(event)is not necessarily inefficient or a bug.If the event is not a key-event, it's convenient.