When importing SFX files to several different actors in my game I ran into, what I assume is a pretty common problem for most developers, overlapping audio! When the player gets hit he plays a hurt sound and when he dies the same happens. The problem is though when the player gets hit for their last health they also die, which causes the whole issue of overlapping audio. Another issue to address with the SFX was what happens if there is multiple spiders on the screen and they're all attack the player at once? Multiple overlapping audios, that's what
This is an important problem to fix as feedback is extremely important to the loop of our game. If that problem goes unresolved and we continue adding new enemies, pickups, and other elements all with their own SFX this can become a bigger problem very fast. On top of having so many sounds coming from so many different places, if they are all overlapping each other, a bullet hell becomes actual hell.
At first I thought an easy solution of a bool would do the trick and this bool would get set to true when the player is dying . I added the variable into the conditional and tested it, but no fix. The core problem with this is this variable would only get set while true in the HandleDeath method. By the time that the variable was set to true the hurt sound has already played because the player always gets hurt before they die. Additionally trying to solve the multiple attack sounds for the spiders with this method wouldn't work either. Each spider making sound was it's own separate entity in the game world
After spending some time thinking and researching how I could stop a sound that hasn't happened yet, I came across a solution. I could use the UAudioComponent, this is a variable that is pretty much a reference to a sound. I assigned this component to whenever the hurt sound was played then used it to stop the hurt audio when it would occur during death. I tried this same method for the attacking audio, but the problem with that is I can't stop a sound right when it plays, believe me, I tried and got an editor crash. Instead I came across an asset type the Unreal offers for this exact problem called sound concurrency. What this asset does is it ques audio of the same type and lets you choose how you want to handle the que. I made it so that if there was a new sound in the que it would be played since there will be plenty of spiders making those sounds in our game.
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.