How can I get music to play continuously from the main menu into a level and back to the main menu?

I’ve tried a few different strategies from seeing YouTube tutorials on this. Problem is my main menu is on a separate game mode. So if I try storing a global variable of that it gets overridden when a new game mode is loaded in my regular levels.

I’ve also tried putting the main menu in the same game mode as my levels. But then I run into issues where the game instance object with my music seems to just disappear after ~45 seconds. So my music just randomly stops after 45 seconds.

Levels right now are chosen from the main menu but I can put a level section menu in game but that’s more of a pain.

Would persistent levels solve this problem?

Anyone have an idea on how I could get a playlist of music to continuously play without interruption from the main menu until the game is exited? I just want the music to shuffle each time the game is loaded up.

Starting it from the game instance should do the trick.

You can also have a persistent level from which you stream all the other levels you want to load. Notice ‘stream’, not ‘load’. Then play from that level.

But like I say, GI should do the trick. What makes you think the GI is dissapearing? Because you would have no game if that was the case…

Thank you so much for the reply!

Yeah, that’s what I thought too but the music just seems to cut out ~45 seconds in when nothing is going on. I’m having a hard time understanding why or how to debug that. All other sounds work fine.

Before the cut out issues, I would run into issues with the GameInstance being recreated when going back to the main menu as it seems like it was re-initialized in the new MainMenu level that loaded in. That caused the music to restart. Does sound right?

You only have one GI running the whole time the game is running. It doesn’t get changed.

Is the audio track definitely longer than this?

Yeah, the audio tracks are 2-3 minutes long each. I’ve triple checked the length of them. I guess I’ll try converting everything to a Streaming workflow with persistent levels. The music would usually get choppy sometimes during big level loads which streaming may fix as well…

You can use the GI without converting to streaming, btw :wink:

I recently published my Persistent Music Plugin which will handle all of this automatically for you through an easy to use game intance subsytem - its free on fab and works with UE5.0 and up :slight_smile:

Yes, persistent levels (or level streaming) can help a lot here, but the most reliable core solution is still properly using a custom Game Instance with Spawn Sound 2D (or an Audio Component) while ensuring “Persist Across Level Transition” is enabled. The separate Game Mode for your main menu is a common source of issues, as Game Modes are level-specific, while Game Instance persists across everything.

Why Your Current Issues Happen

  • Separate Game Mode for main menu: When you travel to a level with a different Game Mode, references/variables tied to the old mode can break or get recreated. Game Instance should survive this, but you need to be careful with initialization.
  • Music disappearing after ~45 seconds: This is a known gotcha. Possible causes:
    • The Audio Component isn’t properly referenced/stored in the Game Instance (it can get garbage collected or destroyed if not held).
    • Auto-destroy on the component, concurrency settings, or sound class issues.
    • Looping + certain spawn methods sometimes fail to persist reliably without extra setup.
    • GC or streaming quirks during level loads.

Recommended Approach: Game Instance + Persistent Audio

  1. Set up your custom Game Instance (Project Settings → Maps & Modes → Game Instance Class).
    • Create variables: e.g., CurrentMusicComponent (Audio Component), CurrentSoundCue (Sound Cue), maybe an array of tracks for shuffling.
    • In Event Init (not BeginPlay) of the Game Instance, optionally start default music or shuffle logic.
  2. Create a custom event in Game Instance, e.g., PlayMusicTrack (input: Sound Cue).
    • Check if the new cue is the same as current → do nothing (prevents restarts).
    • Fade out/stop the old CurrentMusicComponent if needed.
    • Spawn Sound 2D (or Create Sound 2D) with your cue:
      • Enable Persist Across Level Transition (critical checkbox in advanced dropdown).
      • Set to loop if desired (better on the Sound Wave/Cue).
      • Store the returned Audio Component in your CurrentMusicComponent variable.
    • For shuffling: On Game Instance Init or a “Next Track” event, pick a random track from your array (avoid repeats if wanted) and call the play function.
  3. Main Menu and Levels:
    • From main menu (Widget BP or Level BP), call the Game Instance’s PlayMusicTrack with your chosen cue.
    • In level Blueprints (Event BeginPlay), call the same function with the level-appropriate track (or let GI handle a global playlist).
    • Use Open Level (or seamless travel if possible) instead of hard loads where feasible.

This keeps the music alive because the Audio Component lives on the persistent Game Instance.Persistent Levels Alternative/ComplementYes, this can solve your problem nicely and is great for background music:

  • Make a “Persistent” or “Master” level that contains your music actor (Ambient Sound or Blueprint with Audio Component).
  • Load your main menu and other levels as streaming levels into it (not full Open Level).
  • Play the music from the persistent level — it won’t unload.
  • You can still use Game Instance for playlist logic/shuffling control.

This avoids some Game Mode transition quirks and can reduce loading hitches/choppiness you mentioned.Extra Tips for Reliability

  • Sound setup: Use Sound Cues (set Class to Music). Enable looping on the Wave or Cue. Consider streaming assets for long tracks.
  • Debug the 45s cutoff: Print the validity of your Audio Component reference periodically. Ensure the Game Instance reference is always valid. Check Sound Class/Concurrency (Music class often helps).
  • Shuffling on load: Do it in Game Instance Init — it runs once per game session.
  • Back to main menu: Call your PlayMusicTrack again if you want menu-specific music, or let the current one continue.
  • Plugins: There’s a free “Persistent Music” plugin on the marketplace/Fab that handles a lot of this via a Game Instance Subsystem if you want a quicker drop-in.

Start with the Game Instance + Persist flag — it’s the standard method and works for most people once the reference is properly stored. If you’re still hitting the 45s issue, double-check that the Audio Component variable in GI isn’t being cleared and that Auto Destroy is off. Persistent levels are a solid backup/upgrade for more complex setups. YouTube tutorials from Matt Aspland and others cover the Spawn Sound 2D + Game Instance flow well if you need visuals. Let me know specifics of your blueprint setup if you need more targeted help!