how to play a music continuously.

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

when I play a music, and change and scene it restarts, how do I make it play continuously.

:bust_in_silhouette: Reply From: Magso

The AudioStreamPlayer node needs to be separate from the scene, so the scene tab needs to look like this.

New Scene
   > The game scene
   > AudioStreamPlayer

and instead of using get_tree().reload_current_scene(), load the scene and instance it like this.

export var level : PackedScene
var levelInstance = load(level.get_path())

func _restart():
    your_current_level_var.queue_free()
    get_owner().add_child(levelInstance.instance())

but what are the information i need to put,and where i put it.
(im sorry im am new in gdscript)

RichardSilsa | 2019-12-13 01:50

You haven’t said what you’ve got so far so I’m assuming you’ve created the scene and then used get_tree().reload_current_scene() which as it says, will reload everything in that scene including any music.
I’m saying remove the music from the game scene, create a new empty scene and load the game scene and music separately so the music doesn’t restart. However now you can’t use get_tree().reload_current_scene()because it will reload the empty scene. The code I gave you is how to load a scene resource as a child into the current scene.
As for your_current_level_var.queue_free() this removes the previously played game scene so the new one can spawn. your_current_level_var needs to reference the current game scene.
for e.g.

func _restart():
    your_current_level_var.queue_free() //deletes current scene
    your_current_level_var = levelInstance.instance() //sets new scene to variable
    get_owner().add_child(your_current_level_var) //creates the new current scene

Magso | 2019-12-13 02:10