This is actually not a bug, but the expected and intended behavior of any sound that is placed in a level and not marked to ignore the flushing that occurs when you load a new level. In order to do this, you would want to implement these sounds to ignore garbage collection within the Game Instance. We outlined this process in our 4.14 release notes which I have provided a link to below.
In this case I have set the game to pause and a different level to load in order to test to see if the sound persists when moving to a new level.
Here I am spawning a 2D Sound on event begin play of the startup level, and make sure to check the ‘Persist Across Level Transition’ boolean flag. This will make sure the sound does not get garbage collected when loading the new level.
Keep in mind, if you are trying to load the same level, another version of that sound will be spawned since it is tied to EventBeginPlay. You can avoid this by adding some other checks, but this was just a proof of concept to show you how this feature works. If you are trying to use a sound placed in the level, you will need to set the boolean flag either within code, or by loading the asset registry and manipulating through that route.
Let me know if you have further questions or need additional assistance.
thank you for your fast and detailed response. Unfortunately I wasn’t able to describe the issue at hand more clearly. I do not expect the sound to play continuously. I expect the sound to be restarted once the level is reloaded.
I placed a looping sound cue in the level and started the level. I hear sound. The same level is paused and restarted. The sound cue from the old level should stop, since it’s removed by the garbage collection and the new sound cue should be started when the reloading process is done. It worked that way in 4.13, but it doesn’t work in 4.14 anymore.
I just ran another simple test on my end with a looping Sound Cue placed in my level, then calling the game to pause using the ‘Set Game Paused’ function. Then I called the ‘Open Level’ function to reload the same level, and finally unpaused the game to hear the sound re-initialize and play from the beginning.
We added flags and checks in 4.14 to give the user greater control over sounds persisting across level transitions. I can confirm that things are working as expected/intended and what you are reporting is not a bug, but just the currently functionality of the audio framework.
I’m experiencing the same problem here with Audio Components playing a Sound Cue or a simple Sound Wave.
Pausing & restarting the level using OpenLevel (or with the console command “RestartLevel”) breaks the audio of the Audio Components. The more restarts I apply the worse it gets, for example, if I have a SoundCue with a CorssfadeByParam, some of the input sounds will still be audible after the first restart but after several restarts all of them will stop working.
I tested creating the Audio Components in pawn’s Construction Script and at Begin Play Event, both with same results.
Everything works perfectly when I restart the level without pausing the game first.
EDIT: I was able to reproduce the problem on a blank project with an actor that has an Audio Component with auto-activate checked. Pressing pause and then restart breaks the audio.
Only working situations were:
To press pause->restart->pause->pause.
Set pause to false after OpenLevel (This solution doesn’t seem to work on a bigger project, I tried unpausing after OpenLevel, also tried unpausing with/without a delay on Level Blueprint at Begin Play with no luck)
Similar problem happens to us also with 4.14.
Might be that the behavior of the sound transition across levels has been added but what we’ve seen has no relation to that. We are just using sounds, without requiring any transition and they are sometimes played at level start, sometimes they are not. Stranger thing is after we pause/unpause the game, they start playing as they should have at the start of the level (they look as they are queuing somehow).
Please check this thread for more details of the problem, its similar to this one
I am not sure what I am doing differently from what you have explained, but I am getting the correct results whenever I pause the game and re-open the current level using the exact same blueprint scripting you have provided. I have attempted by adding this to the player pawn as well as trying this as a self contained blueprint that accepts user input.
Both cases produced the correct result. I have a simple sound that is set at ‘Is UISound’ so it can persist when the game is paused. I then use the ‘R’ key which is mapped to a level restart input. No matter the order in which I pause, unpause, or restart, the sound plays as expected.
Perhaps I am overlooking a step or I have left out something important that gets this issue to occur, but so far I am unable to reproduce this issue on my end.
Thank you for taking the time to look it into detail. Setting the Audio Component to ‘Is UISound’ solved the problem for me. However, as the name suggest, shouldn’t this only be used for User Interface sounds? Let’s say I have a car and it has an engine sound, if I press pause and ‘Is UISound’ is set to true, the engine sound will keep playing while game is paused unless I specifically stop the Audio Component.
Maybe I’m not understanding it properly, but shouldn’t be the engine’s expected behaviour to properly reload all Audio Components in an Actor/Pawn when a level is restarted/opened even if its not a UI sound? And why does it works fine when after a restart with failing sound, game is paused and then resumed? (I also observed that with ‘Is UISound’ set to false and setting pause to false after calling OpenLevel worked fine in a blank project, but it didn’t work in a a bigger one (Unless I resume->delay->restart), so it doesn’t seem like a reliable solution either)
The background music (non UI sound cue) of my project breaks reliably with the first level change, since my game is always paused when the restart button can be pressed. Pause / Unpause start the sound when it’s muted after restart.
Pause (open menu)->Restart button OnClick:(Unpause->Delay(0.2)->Restart): Worked fine.
When I say that sound doesn’t work is not always muted, sometimes the SoundCue with pitch controlled by param is bugged and you can still hear some noise.
Also as I specified earlier, when playing a SoundCue with a CorssfadeByParam some of the input sounds will still be audible after the first restart but after several restarts all of them will stop working. So in the cases where the sound breaks after a restart (‘Is UISound’ set to false), it gets worse after each restart.
I know it doesn’t make much sense but somehow it fixed the problem in a blank project (not in a bigger one) when ‘Is UISound’ is set to false and game is paused and then restarted. Basically calling SetGamePaused after OpenLevel:
thank you for taking additional time to investigate this issue. Please follow my initial reproduction of the issue step by step. The sound must not be a UI Sound. I can confirm that UI sounds do not cause that issue.
I have Unreal Engine 4.14.2 with hot fix, but I still get the same problem. When I open menu map and then through “Open Level” node I open level every audio works fine, but when I return to menu and then open same level again, some audio stops working!