(GAME JAM, URGENT)How do I keep a song while changing scenes?

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

I have a AudioStreamPlayer2D with a song. Is there a way for it not to start over when the scene changes, but continue playing instead?

Have you tried play in singleton?

shintiger | 2020-01-08 17:45

:bust_in_silhouette: Reply From: Jason Swearingen

I’m a godot newb, so hope someone else helps answer too, but just an idea: try creating a new thread and playing the song on it?

:bust_in_silhouette: Reply From: emrodk

You want to keep the audio node alive so you have two options. First, the scene that had that AudioStreamPlayer2D needs to be on your main scene, this implies that you will never free or restart the scene. And the last option is that the scene that had the audio node needs to be a singleton using the autoload feature of Godot.

Thank you! But is there any way NOT to load a singletone in particular scenes?

Anastasia | 2020-01-08 18:40

The singleton will be loaded at the beginning of your game, always. Try adding a script to the singleton with methods to control the music and you can pause it when is necessary

emrodk | 2020-01-08 19:57

:bust_in_silhouette: Reply From: Jason Swearingen

I think I just stumbled across what you need: Singletons (Autoload) — Godot Engine (latest) documentation in English

Thank you! But i aint very good at using the documentataion. I definetly understand how this works, I just don’t know how to aply it to music.

Note: I dont need this song to be playing in ALL of the scenes

Anastasia | 2020-01-08 14:53

OKAY I figured it out! Problem is that… There is one scene with a diferent song… is there a way NOT to load the singletone during that scene??
UBDATE: The singletone only plays during the menu, where I dont need it playing! When I enter in another it just… Fades out after a few seconds!

Anastasia | 2020-01-08 15:22