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?
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.
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 :
ā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.
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.
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.