Background music throughout Scenes??

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

Uhhh how to make a “background music” play across a the entire scenes without it being paused and played again,

i set up an AudioStreamPlayer attached to the player scene so that the music would play every time a play a level, but as i transition to the next level it repeats itself, any examples on how to fix this?

:bust_in_silhouette: Reply From: Moo

Try creating a global object which continues playing audio between scenes

:bust_in_silhouette: Reply From: Zylann

In Godot, changing scene is actually a shortcut for just removing a node and its children, and replacing it with another scene. Basically, it does this:

- root (Viewport)
    - YourCurrentScene <-- this node will be replaced
        - Player
            - AudioStreamPlayer <-- this one too because it's grandchild of the scene

If you want an AudioStreamPlayer to persist between two scenes, it needs to remain in the tree while you do the transition.
So an easy way to achieve this is to use a singleton node: Singletons (AutoLoad) — Godot Engine (3.0) documentation in English

Then this will happen:

- root (Viewport)
    - YourCurrentScene <-- this node will be replaced
        - Player
    - AudioStreamPlayer <-- this one will remain