How to send a signal to an instance that it was created by an enemy/player?

Godot Version



How can I tell a created object who created it, without specifying the path to the creator?
The creator object - enemy or the player. The object being created - projectile. Each object has its own scene.
The enemy object does not have a fixed path name and can exist in a huge number of copies.
The current view of the creation script, somewhere inside it you need to add a signal.

		if !gun_animation.is_playing():"shoot")
			instance = bullet.instantiate()
			instance.global_transform = gun_barrel.global_transform

use global event bus should be quicker and easier

in your

func _ready():
	EventBus.signal_the_projectile.connect(func():print("do something"))

in your when you want to try to emit the signal:


in the EventBus script AutoLoad:

extends Node

signal signal_the_projectile
1 Like