How i can add extra arguments to a predefined signal C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jee_gbg

Hello, i want to know how i could add extra args to a predefined godot signal that already has args.
I have a Area Body_entered signal and i want to pass not only the body that enters the area, but also the signal emitter.

How i could do this? I didn’t found how to do it on C#.

Thanks

:bust_in_silhouette: Reply From: aXu_AP

I don’t think one can modify existing signals, so the solution could be making your own signal. Make a method on the signal emitter and hook it to body_entered signal. In that function emit custom signal which contains all the information you need to pass.
Sorry I can’t provide you with C# example, I have yet to try C# with Godot (I know C# but quickly learned gdscript and I was quite pleased with it :slight_smile: ).

Now that you mentioned it, it’s quite strange that signals don’t tell who emitted 'em. I mean, C# events usually have the sender object…

Edit: I forgot that you can define extra arguments to be passed when connecting the signal.
You can add the emitter there. Something along these lines:

area.Connect("body_entered", this, nameof(HandleBodyEntered), new Godot.Collections.Array(area));

Hello, i think in GDScript it’s possible to pass some extra args with predefined signals, i will check later. Thanks for the solution! Edit: I had skipped somehow the edit, thanks you!

jee_gbg | 2021-10-28 18:56

No problem. If it worked, don’t forget to accept the answer! That may help others who could be searching for the same question.

aXu_AP | 2021-10-28 20:13