-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
[3.x] Input: add retire option to is_action_just_pressed()
#97529
Conversation
I see a potential problem with this approach. If there are multiple nodes doing this check, then the result will be correct for only one of them. The same happens when there are multiple |
Yup, that's true it will not work for people who expect to query the same action multiple times. To a certain extent I'm trying to brainstorm ideas here. At the moment is it works as expected, but users may need excessive boiler plate for the situation in the issue. They would need to e.g. record the current frame just pressed in their own code, and compare that when checking the second / third time, which is multiple lines of code. I'm also slightly concerned that this report is highlighting an obvious case, but it may have been happening in people's projects to a lesser extent for years (maybe not affecting gameplay much), and it would be nice to have a way of closing the problem.
|
Retired actions will no longer return `true` to `is_action_just_pressed()` in the same frame / tick (unless re-pressed).
d1924c0
to
df4dec1
Compare
is_action_just_pressed()
is_action_just_pressed()
@timothyqiu I've updated this PR to go with adding an extra default argument so that users have to explicitly choose to retire actions. I've also written a similar PR to add a |
Tested locally and this works as expected. It does not create inconsistencies between different parts of the game unless explicitly asked to. Issue-solving-wise, if the user knows/remembers that they should set |
This would re-introduce the old bug of missing input #73339 that is fixed by #77040. The legacy mode was really just added in case of disaster. |
<description> | ||
Returns [code]true[/code] when the user has [i]started[/i] pressing the action event in the current frame or physics tick. It will only return [code]true[/code] on the frame or tick that the user pressed down the button. | ||
This is useful for code that needs to run only once when an action is pressed, instead of every frame while it's pressed. | ||
If [code]exact[/code] is [code]false[/code], it ignores additional input modifiers for [InputEventKey] and [InputEventMouseButton] events, and the direction for [InputEventJoypadMotion] events. | ||
If [code]retire[/code] is [code]true[/code], [method is_action_just_pressed] will no longer return [code]true[/code] for a pressed action for subsequent calls on the same frame or tick, unless the action is re-pressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplifying wording slightly.
If [code]retire[/code] is [code]true[/code], [method is_action_just_pressed] will no longer return [code]true[/code] for a pressed action for subsequent calls on the same frame or tick, unless the action is re-pressed. | |
If [code]retire[/code] is [code]true[/code], [method is_action_just_pressed] will no longer return [code]true[/code] for the given action when called again during the same frame or tick, unless the action is pressed again. |
"unless the action is pressed again" is a bit... vague? I'm not sure what that means in this context, and I'm not sure the reader will, either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's kind of hard to get across in a small number of words, because to some extent it depends on an explanation of how just_pressed
works.
We can do some more revisions of the text if we decide to commit to this approach (as there are a number of ways of addressing the issue), and I'll make this change tomorrow.
A separate retire_is_action_pressed()
function would be just as good, it just depends what we think will be easier for the user to understand.
For
|
Ah I see, I wasn't aware of that (I have limited experience of using In that case there is likely for retiring actions, or a case for your proposal (godotengine/godot-proposals#10843). 👍 |
Retired actions will no longer return
true
tois_action_just_pressed()
in the same frame / tick (unless re-pressed).The retiring version would thus be:
instead of:
Fixes #97526
Notes
_input
reportsis_action_just_pressed()
multiple times per frame #97526 of duplicate "just presses" during_input()
.retire_action_just_pressed()
but this would have ended up duplicating the existingis_action_just_pressed()
version in this PR (minus theretire
argument).false
required forp_exact
, but neither is completely ideal.