How To Stop All Sounds?

Hello everyone,

I am trying to find a way to stop every sound in my game when the Player dies, so that I can play the Game Over Music. I got the Game Over Menu setup, just want to find a way for the rest of the sounds to stop playing.

Does anyone knows how to do this please?

Thanks,

Kyle,

You make an array and add all references of your sound actors to that array. Once the player dies you get each element in the array and you stop the sound using a stop node. I’m not too sure of how to get all the elements in the array at once because the way i did it is probably inefficient.

This is the efficient way of doing it. The ForEachLoop allows you to loop through the array and stop each sound actor. I didn’t know how to do it before but now i know. So your post helped me learn something new :)… Thanks.

Oh, I see, but I am afraid to say that this is not what I was looking for.

I used ‘Play Sound At Location’ on my music, they are not placed on the map. Should I place the music on the map inside using ‘Play Sound At Location’ function instead?

I need the game to know that when the Player has died, all music would stop and a new music would play.

Sorry for the late reply.
You can replace the play sound location with a spawn sound at location so that you have a return node that can execute the stop function. The only problem is that when you try adding those return values to an array, for some reason the music doesn’t stop. You can test it out and see if you can make it work.
Also have you got the game to recognize when the player has died or do you need help with that as well?

Hey, good to see your reply.

I have added the Spawn Sound At Location, but I did not test on my game because I want to show you how it looks in my Level Blueprint.

So, what do you see here is my spawning events from my Enemies. The function will call once when the Player press the button, they will have a long delay to spawn, after the delay the music spawns as well. And then, it will grab the locations spawn points I spawn on the map to my custom event function and that’s when the Enemies start spawning.

After the Player dies, the Music still continues and the Game Over Music doesn’t play.

What you can do now is go to every blueprint that contains those spawn sound at location nodes and then:
1.) drag off the return value of the spawn sound node and promote it to a variable. Name the variables descriptively so you know which sounds you wan’t to stop.
2.) Now that you have your sounds stored in variables you can go to which ever blueprint handles the checking of the players state(if the player is alive or dead) and then you need to drag the event begin play input pin and cast to all blueprints containing spawn sound nodes individually.
3.) From each Cast node, you need to drag the object node and search for get all actors of class and then from that node drag out the array node and search for the get function under the array section then connect the return value of the get function to the Cast’s node object pin.
4.) Then drag the As “blueprint name” pin and promote it to a variable and name the variable accordingly.
5.) Now after the blueprint triggers the game over function you take the blueprint variable you created in step 4 and drag out its return value and search for the music variable within that blueprint. Once you find it drag it into an array, loop through each element in the array and then finally stop the sounds.

There’s pictures below to help you understand.
alt text
alt text

No, the sounds will be stored in variables from any blueprint. You don’t need a specific blueprint for sound.

Ok then you apply the scripting done in the last 2 pictures i sent above in the player character blueprint

In the player character blueprint get a reference of your music class using the method in gameoverbp.png picture.
Then after your game over widget is created get the music from the reference variable you created above, put them all in an array and stop the music within the array using the method in gameoverbp2.png picture. I tested it out and it worked for me.
If it doesn’t work after this can you please send a screenshot of your player character class relating to the game over method?

Yea, the screenshots are fine just hold on a bit i’m looking for a solution to that item duplication error.

Oh, well I did not create Blueprints Classes for the sounds though.

Do I need to create a blueprint for a sound?

Ah, well I still made the blueprints anyway and done solution but the music still keeps playing when the Player dies.

Note that the Game Over Screen happens in the Player Character, not the Level Blueprint.

Okay… well it seems like I counter an issue.

Huh? The screenshot I provided you is the gameoverbp.png method I did.

I also did the gameoverbp2.png method as well.

Sure, thanks.

It’s strange though how it happens to me because I followed everything you wrote and shown in your solution.

Try deleting those get nodes and then put them back again individually.

Well i’m stuck at this point then.:confused: sorry i tried my best :slight_smile: if i find another way then i’ll tell you.

Just tried it and I am still having the same issue with the duplication error.

Argh, it’s okay.

I just do not see why this is just so complicated. I just only want every sound to stop in my game, that’s all but it seems like it’s harder to do it.