The Audio System


Hey everyone. Here to talk about a new system we've developed. 

Audio will always play a major role in most games. However, the thing about most audio systems is that that they are always being triggered by different scripts, and this can really start to become a problem when it comes to settings. With audio being able to play from everywhere how do you ensure that if the player decides they don't want any audio no sound effect slips through the cracks and keeps playing regardless of what your settings say. On that note what about if you pause. You'd probably expect most sound effects to stop when you pause the game. Same goes with something like music. How do you ensure only one song is playing, that it obeys the settings, and that if you need to carry it over through scenes the music will carry over and not conflict with any potential music that might be playing in that scene?

Now an easier solution I found to the unifying audio volume in Unity was that an audio listener has a volume slider. However I wasn't aware of this until a while after, however my solution still works for my implementation. If you just have a general volume slider then that is definitely the way to go. For my case I added an Audio Manager. The Audio Manager is a singleton class that runs along side the Game Manager, and it is designed to be the only thing to interface with Unity's audio systems. 

The way that it works is that the Audio Manager will have all the volume sliders that I wanna set. In this case there's a master volume, sound effects volume, and a music volume. The Audio Manager will handle the music internally, with functions to help it control one audio source that gets carried with it for music, and other functions can call to the audio manager and change it. However for other audio sources the situation isn't the same since they can appear anywhere. So scripts must register audio sources to the Audio Manager which will store it into a hash. Then the Audio Manager can control their volume and play status. 

There's a few issues that came with that, such as what happens to the original set volume of a sound effect. If the developer wanted that sound to play at .5 and the volume is changed how does the Audio Manager know the volume of the original sound? So the solution to that is that the Audio Manager will tell the audio source to play it, and save the provided volume elsewhere.  There's also private/public issues, which could be a good or a bad thing. Since all audio sources are controlled in one place theoretically another script can call to an audio source it has no relation to and start a sound effect. Which isn't amazing, however overall it's a minor issue. 

Leave a comment

Log in with itch.io to leave a comment.