How can I connect the same signal twice?

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

Hello: 3 I have a problem I have created a signal that serves to indicate if an object has collided, if so, it emits it and the same signal connects it to two scripts but it is only emitted in a single script, how can I do so that both are connect, thank you very much in advance.

A signal should be able to be connected to two other nodes. How are you connecting the signal?

exuin | 2021-02-23 16:19

I apologize if some words are not well understood, I do not speak English so I am using google translator:, c.

Thanks for answering: 3, I’m connected to it like this:

script containing the signal:

signal death(object)

func muerte_por_colision():
if colision:
	if colision.collider.is_in_group("players"):               
		emit_signal("death", colision.collider.name)
		queue_free()

first script:

bala = BALA.instance()
get_parent().add_child(bala)
bala.position = get_node("Core/salida").global_position
bala.rotation_degrees = $Core.global_rotation_degrees
bala.connect("death", self, "muerte")  

second script::

bala = BALA.instance()
get_parent().add_child(bala)
bala.position = get_node("core/point").global_position
bala.rotation_degrees = $core.global_rotation_degrees
bala.connect("death", self, "muerte")

Player_0 | 2021-02-23 16:28

Write the names of the area nodes differently before connecting the signal.

SDGN16 | 2021-02-23 17:00

I already did it, it didn’t work for me :, c

Player_0 | 2021-02-23 18:23

:bust_in_silhouette: Reply From: exuin

So if I’m reading this correctly, each script makes its own instance of the bullet. Instances are unique, which means that even if you connect the same signal on two instances, they will not share connected signals. You must have two calls to connect instead of one in both scripts.

You mean I should have another sign?

Player_0 | 2021-02-23 18:13

No, you can use the same signal for both. Just connect it twice in each script.

exuin | 2021-02-23 18:14

So?:

        bala = BALA.instance()
		get_parent().add_child(bala)
		bala.position = get_node("core/point").global_position
		bala.rotation_degrees = $core.global_rotation_degrees
		bala.connect("death", self, "muerte")
		bala.connect("death", self, "muerte")

Player_0 | 2021-02-23 18:22

self refers to the node that the script is on. You will need to connect it to the other node that has the second script.

exuin | 2021-02-23 18:23

I already understood you, sorry I don’t know how is the correct syntax to do it, could you give me an example

Player_0 | 2021-02-23 18:36

In the second connect call, change self to a call to get_node() with the path to the other script’s node.

exuin | 2021-02-23 18:38

I have a problem:, that tries to copy the path of the node but when pasting this “.”

node image
connect image

Player_0 | 2021-02-23 19:09

That’s because it copies the path of the node relative to the scene root. Since the node is the scene root you get that.

exuin | 2021-02-23 19:11

a haha sorry if I do not understand some concepts, would it be this way ?:

bala.connect("death",  get_node("jugador2"),"muerte") 

Player_0 | 2021-02-23 19:26

    bala.connect("death", self, "muerte")
    bala.connect("death", get_node(path_to_second_node), "muerte")

I don’t know how your scene is laid out so I can’t give you the path to the second node.

You can also try asking in the spanish channel in the discord.

exuin | 2021-02-23 22:24

ok I will, I really appreciate the help you gave me since I was really lost, thanks <3

Player_0 | 2021-02-23 22:34