Audio Between Levels: Possible on Game Instance?


Preface - I have used Unreal in the past, but I am extremely rusty as several new projects I am working on use it.

I am currently implementing some audio for a game, and I am wondering what the best method to implement music between maps. In the past, it was suggested that I use a persistent level and level streaming to accomplish this; however, the current projects are not set up in this manner, and I fear the amount of work involved to convert them to the streamed levels.

I had an idea about calling the audio from the GameInstance, as I believe this persists between levels. Has anyone gotten a system like this to work?

Yeah, if you pass an audio component to the Game Instance it will persist between levels.

Awesome, thanks for comment!

Would you happen to be able to point me in the direction of an efficient way to do this? I am essentially having to relearn how to work in Unreal after so long. I’m assuming there is something regarding this function in the doc?

I will quote Dan, epic audio god:
“You play music on an Audio Component, you pass the Audio Component Reference to something that persists between levels, like the Game Instance, the Game Instance passes the Audio Component back to the next level.”

So it’s very doable in normal blueprints, either create your own gameinstance and hook it up to game, or for example cast to the pre-existing one through other BPs. Many ways to go about it.

Got it. Thanks a lot!

i’ve tried it but the music stops as soon as i change maps. what could be the problem,

i’ve created a custom event inside the game instance and hooked it to the (play sound 2d) and created a public boolean variable so i can cast the events once.
here is what i have in games instance :

i hope to hear from u soon, thanks

‘Play Sound 2d’ is like a fire and forget thing. You need to add/spawn an audiocomponent(a sound), and ALSO promote that spawned sound/audiocomponent to a variable. Then it’s this variable that gameInstance keeps track of.


Thank you for this thread!

I’m trying to use this method for a game.

I’ve created an audio component on a dedicated blueprint named BP_Music_System, and I fire the component on event begin.

But how to promote that as a variable and what type of variable would it be?

Variable would be type of itself, “audio component”, and if it’s in the bp as a component, it is already stored as a variable. To create more variables/references to it, plop it into the graph and drag out of the right side. On top of the big list that popups it should say “promote to new variable”! Would have to f.ex cast to game instance and have it store the variable at some point.

Also trying to figure out how to do this - It seems fairly simple, but just can’t work out how to do it ;_;

Anyone in the thread actually managed to get it going?

Hi All,
You can do it like this (Attached Screenshot)
Spawn sound on GameInstance, promote it to a variable, make sure you have checked the ’ persist across level transition ’ on spawn sound function.

I am trying to do this also - cannot see a screenshot here…