You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
one receives a godot Error object as a return type from the connect function.
While this allows to check if the connection was successful, one can never disconnect that lambda again from the signal.
After some discussions on discord, we settled on a design which returns a handle for that connect function call. The handle will look something like this:
Note: names not final and subject to change. Probably they will be called Connector or similar
The connect call taking in the lambda will then return such a handle which allows to later disconnect and reconnect the lambda at will while still retaining the fire and forget (or better setup and forget) way of working which we have today and is quite easy to use:
// setup and forget:
mySignal.connect { arg1, arg2 -> }
// ---// using handle:val handle = mySignal.connect { arg1, arg2 -> }
// laterif (handle.isConnected()) {
handle.disconnect()
}
// later
handle.connect()
// later
handle.disconnect()
The generated code would look like something this:
This also requires proper memory management to be implemented for custom callables, as currently we create a new wrapper each time we send a callable to gdscript. So from the cpp point of view, the callable is a different one when we call disconnect
CedNaru
changed the title
[Feature] Add singal connection handle
[Feature] Add signal connection handle
Mar 28, 2025
When one connects to a signal using a lambda:
one receives a godot Error object as a return type from the
connect
function.While this allows to check if the connection was successful, one can never disconnect that lambda again from the signal.
After some discussions on discord, we settled on a design which returns a handle for that connect function call. The handle will look something like this:
Note: names not final and subject to change. Probably they will be called
Connector
or similarThe connect call taking in the lambda will then return such a handle which allows to later disconnect and reconnect the lambda at will while still retaining the fire and forget (or better setup and forget) way of working which we have today and is quite easy to use:
The generated code would look like something this:
This would ideally be implemented after #760 to take advantage of the api gen's new design.
The text was updated successfully, but these errors were encountered: