How to get sounds to play when paused?

Right now, the player is able to make certain changes to the game state while the game is paused (GetWorld()->IsPaused() == true). We need sound effects to play in response to those changes, but the sounds always seem to want to wait until the game is un-paused.

Is there any way to mark a sound as playable when the game is paused, or tell the world to play all sounds normally when paused?

Never mind – I figured out a workaround.

It’s a bit of an issue for anyone not using Slate, because it seems like you can either try to play sounds through the world (which will pause when the game pauses) or through Slate.

But if you AREN’T using Slate, it seems like you need to do this (adapted from FSlateSoundDevice::PlaySound()):

void PlayMySound ( USoundCue * sound )
{
	FAudioDevice* const AudioDevice = GEngine->GetAudioDevice();
	if(AudioDevice)
	{
		FActiveSound NewActiveSound;
		NewActiveSound.Sound = sound;
		NewActiveSound.bIsUISound = true;
		NewActiveSound.UserIndex = 0; // Not sure what this does ...?

		AudioDevice->AddNewActiveSound(NewActiveSound);
	}
}

The trick is that you have to set ‘bIsUISound’ to true to not be affected by pausing.

1 Like

If you look at Working with Audio in Unreal Engine | Unreal Engine 5.1 Documentation you can see that there is an ‘Is UISound’ flag you can set on a Sound Class. You then set the sounds you want to play in the pause menu to use that Sound Class and they will then play in the pause menu without having to treat them any differently in code.

1 Like