Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning when someone calls Input.is_action ... in _input(event) #316

Open
golddotasksquestions opened this issue Dec 18, 2019 · 7 comments

Comments

@golddotasksquestions
Copy link

golddotasksquestions commented Dec 18, 2019

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

@regakakobigman
Copy link

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?

@willnationsdev
Copy link
Contributor

willnationsdev commented Dec 19, 2019

@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.

@TrickMe
Copy link

TrickMe commented Feb 20, 2020

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.

@TrickMe
Copy link

TrickMe commented Feb 20, 2020

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...().

@golddotasksquestions
Copy link
Author

golddotasksquestions commented Feb 21, 2020

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.

@regakakobigman
Copy link

Please note:
Although the word "just" is missing, event.is_action_...() corresponds to Input.is_action_just...().

Really? That's terribly misleading.

@TrickMe
Copy link

TrickMe commented Mar 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants