-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Allow to discard excessive arguments in signal connection #762
Comments
I would like to connect this with a comment I posted here godotengine/godot#16863 (comment) We could have two signal arguments: func _text_changed(): pass
func _text_changed(old_text): pass
func _text_changed(old_text, new_text): pass |
Sooo godotengine/godot#42683 basically implemented this, but it's not available from editor yet, so I'll keep it open until then. |
Totally second this, it's a common case that leads to code indirection, having to jump from ready to the callback function. This proposal would definitely help shave off some unnecessary lines of code. |
I am unsure why this is closed or rather if it addresses the proposal. Using It does not solve my use case. I do listen to certain events to track actions performed by the player to update goals statuses. Workaround, To connect and ignore the arguments to the signal, and to ignore the number of arguments I can give to
If signal Alternatively if Callable.unbind() could accept let's say (-1) to ignore or unbind all arguments. Currently I would have to do a parser to get all my events and get number of arguments for each so that I can cleanly use Not to mention to the workaround might stop working if Am I missing something or am I going about it in the wrong way ? This all is the relation to Godot 4. |
If you are connecting a signal, you know beforehand how many arguments it has, no? Or are you emitting the same signal with different number of arguments? Maybe you should emit 2 signals? (one with arguments and one without) |
Thank you for your answer and suggestions, emitting 2 separate signals for different purposes might be the solution. I think it sill does not addresses this proposal and use case where you want pragmatically connect to certain signals, and ignore any number of arguments in the connection. Example use-case would be some observer, where you want to listen to list of signals, ignore the arguments as observer just wants to count the number each signal is being called. |
This is partially implemented, see this comment: #762 (comment)
Describe the project you are working on:
Game using lots of signals.
Describe the problem or limitation you are having in your project:
I sometimes want to free an object after finishing animation. I can do it entirely in editor except one thing - I can't connect
animation_finished
signal toqueue_free
, because it emits with one parameter, which makes the call fail. In many cases, I have to add a script just to connect this signal to a method taking unused argument and callingqueue_free
. It's meh. Recently I had my custom signal connected toqueue_free
(without script), but later decided that it needs additional argument in some cases, so the nodes that didn't need this argument are now broken xd (I have to add a script just to work around this limitation now)Other use examples include methods like
If I wouldn't have disabled warnings, I would get "unused parameter" here.
Here's an old issue about this proposal: godotengine/godot#21844
Some people already supported it >_>
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
There could be a flag for
connect
calledCONNECT_DISCARD_EXTRA
(or some other name) that makes excessive arguments discarded, so that the method would call instead of throwing "Too many arguments" error.Alternatively this could be a default behavior, but it might not be a good idea.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Check this PR: godotengine/godot#38289
If this enhancement will not be used often, can it be worked around with a few lines of script?:
Well, kind of. The thing is that with this feature I wouldn't need some of these scripts.
Is there a reason why this should be core and not an add-on in the asset library?:
Because it's about core. It can't be an add-on (although it would be fine for me if it could).
The text was updated successfully, but these errors were encountered: