area_entered Area3D

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

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?

:bust_in_silhouette: Reply From: johnygames

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.

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 on_area_entered(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).

Dumuz | 2020-08-14 18:19

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.

johnygames | 2020-08-14 20:58

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?

Dumuz | 2020-08-14 21:34

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

johnygames | 2020-08-14 23:25

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

Dumuz | 2020-08-14 23:51

Ok, I added a more complete answer.

johnygames | 2020-08-15 00:08

:bust_in_silhouette: Reply From: johnygames

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.