-
-
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
Make C# signal connections straightforward like GDScript 2.0 is #5835
Comments
Didn't C# support events? Something like |
LOL when creating this proposal I really forgot about this one! should I remove this proposal, or it makes sense to make connect that way, or at least then the COnnect function should be removed from C# then! because if its goin to remain then it should be improved! Also keep in mind that using event requires to manually disconnect it, or bugs can happen: public override void _EnterTree()
{
signal += MethodName;
}
public override void _ExitTree()
{
signal -= MethodName;
}
|
I don't think it can be removed easily. The API is auto-generated AFAIK. |
I don't think it's a good idea to remove public event Action Ready
{
add => Connect(SignalName.Ready, Callable.From(value));
remove => Disconnect(SignalName.Ready, Callable.From(value));
}
Not if they are Godot signals, the events generated by our source generators are just wrappers around the |
oh awesome, didnt know that! also I would like to know from you @raulsntos if this proposal makes sense or not! |
We can't add methods to C# events so we can't add the Also, C# events provide type safety since it enforces the callback method to have the same signature as the signal, this is what users that choose a strongly typed language would want so I believe they'll be happy with the new event signals. Users that are not very familiar with C# would also benefit from learning to use C# events since it's a concept they can then use in other non-Godot C# projects. Documentation is still in progress (see godotengine/godot#64930) but basically, you can connect to a signal in various ways: Connect(SignalName.MySignal, new Callable(this, nameof(MyCallback));
// Creating a Callable from a method group
Connect(SignalName.MySignal, Callable.From(MyCallback));
// Creating a Callable from a lambda
Connect(SignalName.MySignal, Callable.From(() => MyCallback());
// Using C# events with a method group
MySignal += MyCallback;
// Using C# events with a lambda
MySignal += () => MyCallback(); It's preferable to use the exposed signal names in the There is an existing issue opened about int a = 42;
MySignal += () => MyCallback(a); The variable var a = 42
my_signal.connect(my_callback.bind(a)) |
ohh awesome, so my proposal became useless at all, because didnt know about |
Describe the project you are working on
Kart Racing Game
Describe the problem or limitation you are having in your project
Currently in order to connect to a signal you must do:
which is cumbersome
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The solution is make it looks like gdscript2.0 which is quite simple:
signal_name.connect(function_name)
or
signal_name.connect( func(): do_stuff_here.... )
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
the solution is:
and lambda support
If this enhancement will not be used often, can it be worked around with a few lines of script?
no
Is there a reason why this should be core and not an add-on in the asset library?
this requires changes on core
The text was updated successfully, but these errors were encountered: