Audio Between Levels: Possible on Game Instance?

Hello,

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.

Hello,

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.

1 Like

I am trying to do this also - cannot see a screenshot hereā€¦

Thanks bud, Iā€™d missed the persist across level argument. Solved my issue :slight_smile:

Here is a screenshot to show how it is done.

1 Like