This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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

in Engine by (23 points)

1 Answer

0 votes

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 :) ).

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));
by (1,100 points)
edited by

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!

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.