How do you stop a 2D sound?

Hello,
I have a widget that plays a sound 2D in its blueprint. How do I stop this sound? Another method that would suit my needs is stopping every sound.

Thank you for reading.

6 Likes

You first need to keep a reference to the sound that is playing. In other words don’t call “Play 2D Sound” because that doesn’t return a reference. Instead, call Spawn Sound 2D which does return a sound reference.

When you have a sound reference you have two options to turn it off/on.

By call SetActive and passing in a true/false as the “New Active” parameter or by calling ToggleActive which will activate the sound if it’s already activated or deactivate it if it’s not.

28 Likes

Did this solve your issue TalkingIsGreat?

I want my music to loop, and I have a button that switches the value on a Boolean variable. How do I make it so that the music stops but still loops when I turn it back on again?

What you can do is create a new Sound Cue. In the Content Browser, right click and go to Sounds > Sound Cue.

Give the Sound Cue blueprint a name and then open it.

Right click the graph and add a new Wave Player node. Select the Wave Player node and in the details panel select your Wave sound file to play and check the “Looping” checkbox.

Update your Spawn Sound 2D and change the source file from the audio file to your new Sound Cue class.

Thank you.

thanx for the first one, it solved my landmine being stepped on, making a little fsssh sound and then stops, when you walk further then bang!
great! thanx

1 Like

Not sure if this was available when the sound cue answer was written but you can now loop audio without making a sound cue. Just double-click on the sound wave asset to edit Detail properties and check Looping.

3 Likes

Thanks :heart:

Thanks

Thank you, I used this to stop a song when hitting “back” on a widget.