play music throughout the game

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

I need music for my game, which i already have, but i don’t know how to implement it so it plays constantly throughout the game, even when switching scenes. does anyone know how to do this?

:bust_in_silhouette: Reply From: Magso

There are two ways of changing scene’s in Godot,

get_tree().change_scene("path/to/scene") #Loads the scene as it is.

or

current_scene_instance.queue_free()
var next_scene = load("path/to/scene")
var next_scene_instance = next_scene.instance()
add_child(next_scene_instance)
#Changes scenes without disrupting other nodes outside of them.

You’ll have to use the latter in order to allow nodes such as an AudioStreamPlayer to exist throughout multiple scene changes.