In this tutorial we're going to use the Autoload functionality in Godot Engine to play music on the background without cuts between scene changes.
Godot Engine has a functionality for creating Autoloaded Singleton scenes. That means you can tell Godot to load a scene automatically and only once, when the game is loading. That scene will remain on the SceneTree of the game even when switching between scenes.
We will use this to have a single stream of music playing on the background of every scene of our game.
You can check the official tutorial on Singleton Scenes on the Godot Wiki.
StreamPlayeras the root of the scene.
StreamPlayerproperties, click on Stream > Load and load the music file.
Autoplaycheckboxes. This will autoplay the music on loop when the scene is loaded.
That's it! Now we have the music playing on the background even if we switch between scenes.
Let's take a look at the scene tree of the game while is running:
In this example we have first the "scene A" and then we switched to "scene B". Notice how the MusicPlayer scene remains loaded even when we switch scenes.
If you want to inspect the scene tree of you game go to the scrips view and then Debug > Show debugger. Then go to the Info tab and click on the refresh icon.
That's all for now. If you found this tutorial hard to follow or if you are just curious I will leave an example project in the download section below.