Stop Audio file playing in Game

Hi, I have made a level where once the game starts I want an audio track to start playing. I want the user to be able to toggle between 3 audio tracks when playing the game. I create a Soundtrack BP and inside I had the 1st track play when game starts, I connected EventBeginPlay to PlaySound2d node and chose the 1st song. That works fine, everytime the game starts the 1st track plays. I want the user to press the Keyboard letter 2 to play song 2, keyboard letter 3 to play song 3 and keyboard letter 4 to stop all audio, and of course when player presses 1-3 keys, I want it to first stop any audio that is currently playing first then play the correct song. I cant seem to do this in BP. What node can I use to stop all audio from playing. For example I choose Keyboard letter 1 in BP, then from output of that node I need all audio to stop playing, then from that node I input Playsound2d and choose 1st song. So it first stops all audio playing then 1st song plats. Any help would be great thanks

Hi :slight_smile:

Instead of play sound, use spawn sound 2d. It gives you a reference, which you can use later to modify or stop the sound.

Thanks, so I add Spawn Sound 2d to add the sound, how do I stop the sound, what node do I need for that?

Drag off the reference you get from the spawn. ‘Stop’ is one of the options :slight_smile:

Sorry, I m not understanding. Here is my BP below. When Level starts I want the Arp_Bounce song to start playing. When player presses 1, I want the Arp Bounce sound to stop then I want the Hello MR song to start?

So What node do I need from 1 keyboard press

Promote to variable

Drag from the variable and get the stop node…

Like this, cause it still doesnt stop the song when I press 1

That will be because you haven’t enable input on the blueprint. In the details, enable input for player 0.

( Details panel of the level BP ).

I tried this, please see below, I compiled and ran and it didnt work and I got a Blueprint Runtime Error : Blueprint Runtime Error: “Accessed None trying to read property NewVar”. Node: Stop Graph: EventGraph Function: Execute Ubergraph Soundtracks Blueprint: Soundtracks

Ok, you just made the new variable ‘new var 0’, so you have to use that here

that’s why you made it… :wink:

nice one, this worked, thanks again for your patience, very much appreciated.

1 Like