Background Audio Not Exporting

Godot Version

4.2.1 mono and 4.3 mono

Question

Hi, I am having a problem with exporting my game with background audio.

I started on 4.2.1 mono with my background audio being handle in an Autoload GameManager node that has a child AudioStreamPlayer. In my Audio Bus layout, I had three buses: Master, BGM, and SFX. Everything was working in the IDE, and I wanted to export my game since I was done with my project. However, when I export my game, my background music did not play, but my sound effects worked. I played around with the settings, and still nothing. When I tried Googling, I did not receive much help.

I went to the Godot Discord server for help, they recommended me to use this fix: Array of audio files working in editor but not when exported - #3 by system. Same results - sound effects worked, background music did not. After mentioning that I haven’t upgraded to 4.3, the users thought it might be worth a shot. Same results.

I tried separating the BGM AudioStreamPlayer to a separate scene (BackgroundPlayer.tscn), having the bus be both Master and SFX, replacing BGM, place BackgroundPlayer in each level scene, and messed with more export settings. Same results - Background Music and SFX working in IDE, only SFX working exported. I feel like I’ve tried everything that I can think of and then some.

Can anyone help me on what is going on? I feel like I am running into a brick wall trying to figure out why my background music is not playing when exported, but it is playing while in the IDE.

Thanks.

Hello, I have an update that I found out after banging my head at the wall some more. Apparently, if I loaded a stream, set it to auto play, and exported it, my BackgroundPlayer will work for the first scene BackgroundPlayer is loaded in but never again on the other scenes despite being an Autoload/Singleton.

I think I’m a step closer to figuring it out, but thought I should let people know to any poor soul who is struggling as I had.

Okay, I fixed it. My file loading did not work, so instead, I called a reference to the AudioStream I wanted to use.

So, instead of this:

public void LoadBgmOgg(string path, bool loop = true, double loopOffset = 0)
{
    if (string.IsNullOrEmpty(path)|| !FileAccess.FileExists(path) || !path.Contains(".ogg"))
        return;

    if (Playing)
        Stop();

    path = path.Replace(".import", "");
    var stream = AudioStreamOggVorbis.LoadFromFile(path);
    stream.Loop = loop;
    stream.LoopOffset = loopOffset;
    Stream = stream;
}

I did this:

public void LoadBgmOgg(AudioStreamOggVorbis stream)
{
    if (stream == null)
        return;

    if (Playing)
        Stop();

    Stream = stream;
}

I probably should look into file loading some more, but I’m just happy that I finally got it working.