How to connect a signal to another node in a different scene

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

Hello. I am trying to connect a finish flag(switch scene to menu when the player body enters) to my menu. I am using a signal to connect. I am unable to connect the normal way due to them being in a different scene. How should I do this?

My code for switching scene and emitting the signal:

func _on_Area2D_body_entered(body: Node) -> void:
	get_tree().change_scene("res://Menu.tscn")
	emit_signal("finish")
:bust_in_silhouette: Reply From: ChristophtTheSchmidt

Hello :slight_smile:
This is not a direct answer, but I think it is not possible to emit the signal after the scene has been changed. The change of the scene will (I think) free the old scene from memory before loading the new one.
My workaround would be:
Create an autoload (Singleton). This is a script which will be active all the time and can be accessed from everywhere by its name (look up how to set up an autoload script).
Then when the menu loads (_ready func) let it check with the autoload if the finish flag has been reached. Then let the menu react accordingly.
Hope this helps!

:bust_in_silhouette: Reply From: the_maven

To instancing with signals:

To change scenes: