In this guide we are going to create a simple one-shot sound and play it in our demo project. This is a sound that plays once and does not loop. FMOD uses Events to play sound. To create an Event navigate to the ‘Events’ tab on the left and right click under it. For this event we’re going to use a 2D Timeline Event and name it something suitable.
Now drag your sound file into FMOD in the track in your Event. Ideally your sounds should be in WAV format though FMOD will accept most other formats. You can now play your sound and adjust the level. Here I have a wood impact sound, and I have named the Event ‘Impact_Wood’.
Banks contain the sounds which you create in FMOD. Unity loads these Banks and then references them to play your sounds. So, the next step is to assign your new Event to a Bank. To do this right click your Event on the left-hand column and assign it to a Bank. By default, the mod project has a ‘Master’ and ‘Mod’ bank. You can use either or create your own if you wish. I’ve assigned my Event to the ‘Mod’ Bank.
You’ll see that this got rid of the ‘::unassigned’ warning. To see what is currently in a Bank you can go to the ‘Bank’ Column and open up the Bank.
FMOD uses a mixer to mix your Events together. To view it click ‘Window-Mixer’. The mod FMOD package comes with two Mixer Groups – ‘Mod_Music’ and ‘Mod_SFX’. You want to assign your sound to one of these Groups, it will allow the player to control the volume of your sounds using the in-game options menu. To do this simply drag your event into a mixer Group in the left Routing column.
Never delete and remake these mixer groups. They rely on a custom GUID which is coded into Wobbly Life. If you delete and remake them this link will be broken.
Building the Banks puts all your Events into Bank files that Unity can read. To get any changes you make in FMOD into your Unity project, you will always need to build the Banks and transfer them over. To build the Banks click ‘File – Build’.
By default, the Banks will build to the ‘Build/Desktop’ folder inside your FMOD project folder. Remember where these files are as you will need them later.
In your Unity project create an empty GameObject. I’ve called mine ‘AudioEmitter’. Add the ‘Mod Sound Emitter’ component. For neatness put the Transform of this object as 0,0,0. This is a basic sound emitter that will play an Event on Object Start or Object Enable. For any more complex functionality you will need to create your own script.
To play your Event the script needs the Event path. To get your FMOD Event’s path, right click the Event in FMOD and click ‘Copy Path’.
Paste this Event path into the Mod Sound Emitter component and set the Play Event dropdown the ‘Object Start’. Your component should look something like this.
This emitter will now play a 2D sound whenever the level starts. So regardless of where the emitter GameObject is we should hear the sound. But before we can test it, we need to tell Unity to load the Banks we made earlier.
To get Unity to load the Banks we need to use the ‘ModRuntimeManager’ component. Create an empty GameObject and attach this script to it. We need to populate the ‘PreLoadBanks’ array in this component with our Banks files. Unfortunately, currently this script only accepts ‘byte’ files instead of the ‘bank’ files that FMOD generates. So, before you drag the files into the ‘ModRuntimeManager’ you need to rename the file suffix. One way to do this is to copy/paste these bank files into your Unity project directory and rename them there. To find the default location your bank files were generated please see the Building the FMOD Banks chapter. Below I have copied these Banks files to a ‘FMODBanks’ folder in my Mod project folder. Then I’ve renamed the .banks suffix to .bytes there.
This allows me to find these files in the Unity Project window and assign them to the script there.
Note: You can also change the directory where FMOD generates the banks in the FMOD project itself which can speed up this process.
The next step is to test the mod to see if you can hear your sound play. Bear in mind your one-shot sound will play as soon as the level loads – you may even still be coming out of the loading screen! But if you hear you know that your FMOD project is working properly in your mod. For more information on how to test a mod see the Testing Mod.