How do I stop a sound?

I want to switch from one sound to another. How do I do that?

When you spawn a sound you are returned an Audio Component Object reference. You need to store this in a variable so that later when you decide to stop the sound, you can call the Stop function on it.

For example in the attached screenshot (It looks like you’re using “Spawn Sound at Location”), I call Stop on the Audio Component Object reference.

2 Likes

You need to create audio component as UE4 sound system centers around it, it is kind of like sound handle same as timers have a time handles. Audio component is bound to the single sound asset, component also have individual audio controls, so you stop the sound, use “Set Sound” to set new asset and then Play it. You should have audio component on actor that it suppose to play sound from, if you want to play sound more globally you can also placed audio component on Player Controller (in there no local multiplayer) as well Game Mode if it’s single player, as placing it on player camera or pawn may work too. There also Ambient Sound actor which is actor that just contains audio component that you can place on the level, you can try that too

There also “Create Sound 2D” or “Spawn Sound at Location” node which return anonymous audio component from which you can control the sound (you also need to Play sound on it as it only creates the component), but remember to keep in in variable as it might be cleaned by GC.

You can also use function Delay to stop it if you know how long you want it to play before starting the new sound. My example adds a wave sound when the 1 key is pressed, plays for 2 seconds, stops, then plays another wave sound for two seconds, then stops. You can create a variable also and use that to plug into the Duration slot.

1 Like

You should reuse audio component instead of creating new one

That is not what I want. I want one sound to play on play and for it to end and another sound to play on trigger.

I know this is four years old, but replying for other people that might still have this issue.

If you are playing a 2D sound, go to “Concurrency settings” and add a Sound Concurrency
image

If you add a new SoundConcurrency

You can set it to only allow 1 concurrent voice in this group, and to stop the oldest sound.
image

This worked for me. Now when it plays a new sound, the old one stops. There are some useful settings in there to play around with too.

I hope that helps someone

1 Like