How do I get another node from a different scene to receive a signal?

Godot Version

v4.2.1

Question

So I am new to Godot and I am trying to receive a signal from my “mob” scene in my “Survival_Game” scene. The node emitting the signal is “mobs” but I am not able to retrieve this node in my “Survival_Game” scene to receive the signal. I’ve tried many methods to try to get this node but right now it looks like this:

func _ready():
var mob_scene = preload(“res://mob.tscn”)

get_node("/root/mob/mobs").death.connect(self._on_death )

“death” is my signal and the function “_on_death” is what I’m trying to trigger with the signal. However, I get this error when trying to run the program:

E 0:00:00:0948 Survival_Game.gd:13 @ _ready(): Node not found: “/root/mob/mobs” (absolute path attempted from “/root/Game”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1635 @ get_node()
Survival_Game.gd:13 @ _ready()

Any help would be much appreciated. I haven’t been able to find my solution online so far.

Thank you

Did you add the other scene to the tree? You seem to just preload it, you can’t access nodes that way

I added the “mob” scene to the “Survival_game” scene so that I can connect it directly from there. Then I marked the little placeholder option so that it didn’t spawn in. I don’t know if that’s how I’m supposed to do it but it works.

func _ready():
var mob_scene = preload(“res://mob.tscn”)

From here you need to do something like:

mob_scene.get_node("mobs"). death.connect(self._on_death)

If the signal is buried many nodes in a new scene, you should creat a helper function in the base scene script to return the node you want to connect, or pass the function you want to connect the node to signal.

Anyway you should try to connect the signal when the scene is created.