Connect signal of a scene that is instantiated after timer timeouts

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

I have World scene, Enemy scene and Timer - when timer timeouts the Enemy scene is instantiated into World scene… now I need to know when the Enemy scene is queued free. So I created signal and emited it when Enemy scene is queued free - but how do I connect that signal to World script? I cannot do it through Node panel and via code there is hint connect(“Signal name”, callable) but the signal is not declared in World scene because the Enemy scene is instantiated during game.

Older tutorials for Godot 3 suggest get_parent() which is not possible now in Godot 4 and I also want to avoid those get_parent() things.

:bust_in_silhouette: Reply From: Wakatta

Try the following

signal queue_freed

# Keep a reference to your world scene in your enemy scene
@onready var world = get_node("path/to/world_scene")

# Emit signal when this node is freed
func _exit_tree():

func _ready():
	connect("queue_freed", Callable(world, "on_enemy_death"))