How can you get the name of a signal emmiter?

Description

I’m now making a platformer game and wanted to implement a checkpoint system that involves getting the name of a signal emitter which is an Area2D. Here is an outline of what I want to do

var Player = self.get_parent().get_node("Player")

func Checkpoint_Touched(body):
	if body == Player:
		$Signal_Emitter.position = Player.SpawnPosition

Signal_Emmiter is replaced with the name and SpawnPosition is a custom property

Godot Version

4.3

If body is the signal emitter then body.name will get the name of the emitter. Is that what you meant?

signal checkpoint_touched(body: Node)

checkpoint_touched.emit(self)

_on_Checkpoint_touched(body):
    print(body.name)

The signal is built-in, not from a script. That’s what makes it difficult.

In the originating script you could wrap the signal in another signal, something like :

signal built_in_signal(built_in_data)
func _ready():
	built_in_signal.connect(_on_built_in_signal)
	
signal enhanced_built_in_signal(built_in_data, orgin)
func _on_built_in_signal(built_in_data):
	enhanced_built_in_signal.emit(built_in_data, self)
1 Like

I would prefer not to create numerous scripts for each checkpoint, as this would result in an excessive number of script files in my project. Such an accumulation would lead to a mess, with each file containing similar code, which I aim to avoid.

Assuming the signal has the same name on each checkpoint, the script wouldn’t need to be different for each instance. You just attach the same script to each one.

1 Like

You are a genius! Thank you so much!!! :partying_face: :partying_face: :partying_face:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.