0 votes

Hi everyone,

up until now, getting a signal from another scene is a pretty straight forward thing to do:

$"../SceneName".connect("signal_name", self, "signal_name_received")

However, for some reason I don't succeed in getting a signal from another scene that itself is within another scene. (Error: get_node: Node not found: ../SceneName.)
I tried the path as well:

$"res://scenes/SceneName.tscn".connect("signal_name", self, "signal_name_received")

But nothing works.

What am I doing wrong? How can I set up the path to the signal-emitting scene?
Any suggestions?

in Engine by (434 points)

1 Answer

+1 vote
Best answer

You need to connect instances of the scene, not the scene file itself:

var scene = load("res://scenes/SceneName.tscn").instance()
scene.connect("signalname", self, "signalname_received")

Preloads work, too (I'm assuming you already know how to arrange preloads):

var Scene = preload("res://scenes/SceneName.tscn")
var scene = Scene.instance()
scene.connect("signalname", self, "signalname_received")

by (212 points)
selected by

"at that moment", so it's not permanent, and that makes sense then! Thank you!
You are right, I realise I didn't grasp Nodes completely yet...

This question may help clear some things up, but the docs will probably be more useful.

Very helpful indeed, thank you!

Such paths can get quite long. And rearranging/adding/removing Nodes would disconnect everything affected...
But there is the extremely useful "find_node":

var some-name = gettree().getroot().find_node("SpriteButtonBase")
some-name.connect("that_button_was_just_released", self, "that_button_was_just_released_received")

This should always work, no matter if the tree is being changed etc.

You can also use export variables for NodePaths that change during development. The editor will let you pick any node from the scene tree while editing in the object inspector.
export (NodePath) var TargetPath

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.