-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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 signal for detecting action toggle states (pressed/released) in Input
#43646
Conversation
Thats amazing! ❤❤❤ Thank you so much, I did not expect anyone would pick this up, definitely not that fast! |
The But one may also say that all actions are in "released" state while the game is started. When a player presses a key, then the state is changed from "unpressed" to "pressed" ( It's also totally possible to add separate signals for this:
I'd personally add two signals, but I'm being conservative with this PR to increase the chances of approval. 😃 Also, if we add two signals for each pressed/released events, then it's also possible to connect two signals to the same method, if someone wants the functionality behind unified Think about this as That said, it's also possible to rename the signal to |
Input
Input
Input
Input
Interesting, thank your for the explanation! I had no idea about any of that. To be honest as someone who is not intimately familiar with the source code and just uses GDScript, and already existing Editor functionality, I find Input "states" more confusing than anything. Input Map "state" is only mentioned here like a sidenote once. I did not feel like it played any relevant role until now, I actually did not pay any attention to it. |
+1 for this approach. |
Yes, I think can be renamed to The only difference with But yeah, TODO: emit |
To be honest I find the button and Input behaviour quite confusing, and from a beginner perspective unreasonably inconsistent. To my novice mind, a virtual button should not be any different than a physical key button on my keyboard or the buttons on my mouse. Methods: (used to check for ongoing property states) if $Button.is_pressed(bool):
if $Button.is_released(bool):
if $Button.is_toggled(bool):
if Input.is_pressed("action"):
if Input.is_released("action"):
if Input.is_toggled("action", bool):
if Input.is_strength("action", float): Signals: (used to check for one_shot events) _on_Button_pressed(button):
_on_Button_released(button):
_on_Button_toggled(button, bool):
_on_Input_pressed(action):
_on_Input_released(action):
_on_Input_toggled(action, bool): Pressure sensitive Input devices are not common place (yet, aside from music and art production), but maybe in future |
This seems like a very welcome addition. I have recently been wondering why this doesn't exist as well. Quick question: Does this allow you to set up a signal per InputAction in the Input Map (so when I often need to know when the |
If you're asking whether raw keyboard/mouse input events would emit a signal, then no, it only applies to input actions defined in the Input Map (namely, input events caught in That said, this will emit a signal for any action indeed, currently there's no way to filter out specific actions, although this is in theory possible to implement. The way I see it, may be actually possible to dynamically add a dedicated signal for each action in the Input Map. In fact I've come up with extends Node2D
func _ready():
for action in InputMap.get_actions():
var args = [
{ "pressed" : TYPE_BOOL }
]
Input.add_user_signal(action, args)
Input.connect("action_toggled", self, "_on_input_action_toggled")
func _on_input_action_toggled(action, pressed):
Input.emit_signal(action, pressed) You could then connect specific input actions like so (instead of general-purpose func _ready():
Input.connect("ui_accept", $AnimationPlayer, "play") I can try and see whether it's possible to do in C++, thanks for suggestion @Arecher! 🙂 |
Implemented via user signals, won't affect documentation.
So yeah I've got it working already per action: func _ready():
# For any action.
Input.action_toggled.connect(Callable(self, "_on_action_toggled"))
# For specific actions defined in InputMap.
Input.connect("ui_accept_pressed", Callable(self, "_on_ui_accept_pressed"))
Input.connect("ui_accept_released", Callable(self, "_on_ui_accept_released"))
func _on_ui_accept_pressed():
print("Pressed: ui_accept")
func _on_ui_accept_released():
print("Released: ui_accept")
func _on_action_toggled(action, pressed):
if pressed:
print("Pressed (toggle): " + str(action))
else:
print("Released (toggle): " + str(action)) Those user-defined signals won't be reflected in the documentation, so this behavior will have to be documented in Each action requires adding two signals per action: one for "_pressed", and one for "_released" events. Those are appended to each name. If you'd like a specific action to work like in "toggle" mode, you can just connect both signal to the same method. |
Closing as this contributor can no longer update this further. |
Yet another PR that is worth continuing regardless of any issues that might have happened with this particular contributor... |
@Zireael07 We can't in good conscience merge their work now even if we approve the feature, because we have to assume they don't want their code to be included in the project anymore. But if anyone is willing to salvage this work, they are more than welcome to! |
You could just ask him, he still exists. |
This user has been banned from the Godot community for repeatedly breaching our Code of Conduct, so no, we're not going to ask. |
Closes godotengine/godot-proposals#1853.
Documentation and further improvements can be written later, if the feature is desired/approved.
To-do:
action_toggled
: Add a signal for detecting action toggle states (pressed/released) inInput
#43646 (comment).Input
#43646 (comment).action_press
andaction_release
methods as well.CoreStringNames
for signal, to optimize for performance somewhat withStringName
usage.Works for those "just" pressed/released events. Will also emit signal while simulating action presses.
With GDScript 2.0: