Calling a one-shot sound effect in FMOD is a quick and easy way to add short, one time only sound effects to your game. This tutorial assumes you have already set up FMOD in your project, if you haven't you can check out the tutorial here.
Create your audio Event
First, you will need a sound effect and to create an event for it. In our example we will be adding a short 'confirm' UI chirp Event.
In FMOD, right-click inside the 'Events' panel and click 'New Event'. In the example below we have a directory to help organise all of our events, and since our sample is going to be for the UI, we have nested it inside of a directory called UI.
Once clicked, name the Event however you like, we have named ours 'Confirm'. On creation, you will notice our new Event has a tag that says '#Unassigned'. This means it is currently unassigned to a bank. In our example we want to split our audio into banks to make it easier to organise down the line. This is super important for larger games.
To do this, right-click on the Event, 'Assign to Bank'->'New Bank'. Type in the name for your new bank, we have used the name 'UI'.
Next. let's create our Timeline Sheet, in the Event window click anywhere, then click on the item 'Add Timeline Sheet'.
Then right-click on the Master track and click on 'Add Audio Track'.
Now we have our Audio Track, let's add a sound effect. We have a UI chirp that we would like to add. You can drag and drop the audio in the Audio Track.
We've imported the sound effect in, but it's tiny! We can fix that by scaling the viewport. Hover your mouse over the edge of the slider, and bring it in to zoom into the audio sample.
Ah, that's better. We can start editing this audio sample to get a better sounding result.
Editing the audio sample
The audio sounds great as it is, but we could improve it. There's silence at the start, so to improve player feedback we could shorten it and add a small fade-in to soften the sound. We could also shorten the audio tail, and add a small fade-out to soften the ending. When audio samples are abruptly cut short when playing they can sound too poppy and can detract from the quality of your game.
To shorten the start of the audio sample, hover your mouse over the start of the audio sample, and drag it in. We want to leave a little gap to add a fade in too. To add the fade in, hover over the top left corner of the audio sample until your mouse changes icon to the 'fade in' icon.
Your audio sample should look something like this.
Now let's do the same with the audio tail. The audio stops at about 0:00:160, so lets crop it to about 0:00:200, then start a fade out from 0:00:160. This ensures a snappy quick UI audio sample.
Great! Our audio Event is now game ready, so let's build it so we can use it in our game!
To Build the audio, click 'File'->'Build All Platforms'.
After a few seconds the progress bar should disappear. Upon navigating to Unity, it will register the changes and update. Once this prompt is finished, Unity will have updated all of FMOD's banks.
Calling the One-shot audio sample
Before we get into coding, we need to find an audio Event identifier before we can trigger it. In the Event window, right-click the Event you want to reference and click on 'Copy Path'. This is the reference that we will use in our code to trigger it.
Let's now navigate to your IDE and the script that you wish to use to trigger the audio. In our instance, we want the Confirm audio Event to be triggered when the game can confirm the player's selection.
At the top of your script, add the using FMODUnity library.
Then find the part in your code where you want to add the sound. Inject the following into your code.
Now if you test, you should hear your sound! This is the quickest way to play a sound using FMOD, but a one-shot sample does not give the most control. In this instance we are playing the sound in '2D', meaning the StudioListener distance to the sound source does not effect volume or the panning of the sound. This is perfect for menu or UI sounds, as volume and panning in most cases needs to stay static.
If you're having trouble...
Make sure that your MainCamera has an FMODStudioListener component. During the FMOD setup wizard, it will do it's best to replace any of your projects Unity native Audio Listeners with FMOD's Studio Listeners. You need at least one of these in your scene at all times to 'record' audio.