+1 vote

I have a script connecting the 'area_entered' signal to a function in another scene.

The signal naturally passes the area that has come into it, but I have a bunch of instances that call to the same function to do the same thing. I need to know which area is being hit. Is there a way figure out what object/signal is calling to my method when the player hits it?

in Engine by (293 points)

2 Answers

+1 vote
Best answer

I do not think you can modify the existing signals to carry more parameters.
you can always create your own signals. Create an autoloaded script and create a signal there. Then emit the signal when an object is hit and have it transfer any info you need. The trick is to emit the signal from the object whose ID you want to capture.

by (1,838 points)
selected by
0 votes

I guess you could call the get_instance_id() method on the area that is touched. This will return the unique id of the area, which you can later use to identify the object.

by (1,838 points)

Right now I have to have the player's Area node identify the Instanced Area incoming, using the default 'area' parameter that is passed. That players onareaentered(area) function is then doing what it needs to do.

But my problem is that I would like to pass the ID through the pre-made signal in Godot "area_entered". I tried to add a parameter to the connect method, but it ignores any other parameters I add. Using the default 'area' parameter that passes the 'Area' that entered it, not vice-versa like I need (The Area that It is entering).

Could you not emit the signal from the Player? Instead of emitting from the incoming area, you could have your game detect collisions with the Player (and vice versa). It all depends on which object emits the signal.

Besides, you can always create your own signals. Create an autoloaded script and create a signal there. Then emit the signal when an object is hit and have it transfer any info you need. The trick is to emit the signal from the object whose ID you want to capture.

I am not sure I understand what you are trying to achieve, so correct me if I am wrong.

Yeah, right now I have the first thing you said happening and I have it working.
And I'm sure I can make a custom signal with a connect to work the way I want.

I was just wondering if there was a way to manipulate Godot's premade signals to pass more complex parameters than what is in the "Connect a signal to Method" window.

'Cause for example Area's premade 'area_entered' signal passes the 'area' that is incoming:

So, if wanted a coin to call to the func on_area_entered() using the pre-made area_entered signal; it would tell me it was the Player's associate Area node that entered it.

Whereas, what I want is the coin itself to tell me which coin ID it is that is being entered, out of a pool of instanced coins. Calling to the same function, in the same script, using the pre-made area_entered signal. Does that make sense?

Yes I see what you mean. I do not think you can modify the existing signals to carry more parameters.

Gotcha, I think you're right. Can you make that reply an answer so I can select it as answered?

Ok, I added a more complete answer.

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 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 webmaster@godotengine.org with your username.