how to emit signal from one scene to another?

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

i want to emit a signal from one scene to another with an argument. please help me with a simple script. thank you.

Have one script emit a signal (ensure that this script is attached to a node). Go into the Inspector and select the created signal. Select the receiving script, and place the function which is to receive that signal into the receiving script.

For example, you have a signal

 signal play_music

Which is emitted in some function

func song():
    emit_signal("play_music")

You then connect it to the node named Music via the Inspector. In the script for Music you write a function such as

func on_play_music():
   # Play good tunes here

Hope that clears things up. For more info, check out the signals documentation.

Ertain | 2019-06-21 00:12

:bust_in_silhouette: Reply From: Squabix

To do that you will need to use singletons.

Create a scene called “Global.tscn” and a script called “Global.gd”. Then go to Project → Project Settings and switch to the “AutoLoad” tab. Select those files and auto load them as “GlobalScene” and “GlobalScript”.

Please look at Godot’s Singleton Tutorial to learn more.