Week 24: How to add SFX to you game without going mad

EarlyOwl
5 min readJan 22, 2022

Hey everyone. Welcome to the 24th week of game development! This week was the ‘Audio Sprint,’ which is meant for working on all the audio-related work. I had added a lot of game interaction in the last few sprints. But they were all working in silent mode, making the game lackluster.

So I decided to use this sprint to add sound effects to all sorts of interaction — UI buttons, player picking up items, spawning new magic weapons, battle mode initiation, enemy’s death, etc.

I had 3 things to do

  1. Collect all the sound effects the game needs as of now.
  2. Code all the events which triggered the sound to play.
  3. Attach all the sound files to their appropriate game events.

But I ended up facing 3 challenges…

1. Finding the best suitable sound effects takes time.

Even at the prototype stage, I have quite a bit of unique interactions that require their own unique sound effects. Finding the right ones which fit your game theme and the overall feel will need you to search, play and test different sound files. Even if you have subscribed to a sound effects library, you still have thousands of files to listen to and pick out the best.

So I decided not to do that at this stage. My aim was to get the playable prototype ready, and when the theme of the game is finalized, I might have to change the sound effects anyways. So instead of meticulously searching FreeSound.org, I swiftly scanned through a sound effects library I already owned and picked up files that were generic and matched their intended purpose. If it somewhat conveyed what was happening during interaction in the game, it was good enough for me.

2. Managing 100s of sound effects in the game

Even at this early stage of development, I have about 30+ sound effect files to work with. And this number is only going to go up. Managing all those could become difficult unless adequately planned. Also, as I am using only temporary sounds, I will have to update all of them in the future. And at that time, I don’t want to check each game object and prefabs to see what sound files are they using and switch them to the new ones one by one.

So I decided to take a different approach. I wanted to have access to all the sound effects in one place. That way, when the time comes to replace some of them, I don’t have to go looking for different game objects.

I created a Scriptable Object holding different sound clips for different game interactions.

Then I changed the code to hold the Audio Collection scriptable object instead of the clip.

This solved the managing problem for the future. And I resumed my work. I continued to import different sound files, coded the triggers for various sound effects, and tested them in the game. That’s when I hit the 3rd Challenge.

3. All the sound effects cannot play at maximum volume.

This might be obvious for many of you, but I was made fully aware of it when 10 different sound effects started playing simultaneously during runtime. All of them playing at max volume blasted my ears off. It was pure noise pollution. And some of the sounds were repeating so often that they got annoying very quickly.

To reduce the noise clutter, I had to make some of the sound effects play at a lower volume than the rest. And to solve the repetition problem, I had to randomize the volume and pitch of the sound files every time it was played. So I did this for those sound effects…

This solved my issues. But again, it created problems for the future when I would replace the audio file. The new one might require different adjustment values, and I’ll be left to hunt the script and tweak the values one by one.

So once again, I went to the Scriptable Object and added a new ‘Sfx’ class and some functions.

Added a new class called Sfx to handle volume and pitch settings
Added some functions to Play Sound and Stop sound in Scriptable Object — Audio Collection

This made the trigger code simpler again.

Now, I don’t have to worry about the individual script. I can use the scriptable object to update the sound file and tweak each sound’s volume and pitch settings. While testing the game, I can tweak those settings from the editor itself and make sure they work exactly as I prefer.

Closing thoughts

For a simple game setup, this should do it. But for an adventure game, you would want the sound effects to fade in or out when the player moves towards or away from the source. I haven’t figured that one just yet, but I’ll keep you posted. That’s the task for the next Audio Sprint.

What’s next?

So that was the progress. Next week is the ‘Gameplay Sprint.’ Now that the prototype of basic mechanics is ready, I’ll be trying to build some meaningful and fun levels with it. I have been waiting to create a coherent game level since day 1 of this journey. So I am super excited about it. Can’t wait to share that with you all!

That’s it for this week… See you next time.

I wish you the very best!

Originally published at https://www.theearlyowl.com on January 23, 2022.

--

--

EarlyOwl

📱 App coder, 🎮 Game creator, 📖 Storyteller - Sharing all that I learn along the way! Sincere hobbyist | Forever a Work in Progress | Learning out Loud