Audio System for FMOD is a tool designed for managing and utilizing the FMOD engine in a simpler and unified manner within Unity. It makes it easier to manage all game audio using FMOD and allows the user to focus more on audio and sound design.
You can also use the "Install from Git URL" option from Unity Package Manager to install the package.
https://github.com/Studio-23-xyz/com.studio23.ss2.audiosystem.fmod.git#upm
This package cannot function on its own and is intended to be used with FMOD. Make sure you have the FMOD for Unity plugin installed in your project before installing Audio System for FMOD. You can find the plugin on the Unity Asset Store or on the FMOD website. This package assumes familiarity with FMOD for its usage so please read up on FMOD's documentation.
- Follow FMOD's documentation on where to set up your FMOD Project.
- After the FMOD project is set up, build your FMOD project for all platforms.
- In Unity, go to FMOD -> Edit Settings.
- Under Bank Import, set Source Type to Single Platform Build and specify your desired platform's build directory.
- This package does not support Source Type of FMOD Studio Project or Multiple Platform Build.
- To build the Unity project for other platforms, select the desired platform's build directory from the FMOD settings before building for that platform.
- In Unity, go to FMOD -> Edit Settings.
- Under Initialization, Load Banks can be set to All, None or Specified.
- If set to All, then you don't have to worry about bank loading/unloading other than the banks for dialogue audio tables. This may not be the best option for larger games.
- Ideally, it is better to set Load Banks to Specified so that you can specify important banks to be loaded on game start. For example, you can specify the master bank(s), .strings bank(s) and banks that are always required (such as a UI bank, base dialogue bank).
- Specified banks cannot be unloaded. Don't specifiy a bank you may need to unload such as a localization bank.
- If set to None, make sure to manually load the Master bank and Master.strings bank before trying to playback any audio. If you have more than one Master bank, then load those and their corresponding .strings banks too.
When setting up localized audio tables in FMOD Studio, the project locales must be renamed or else the data generation will be incorrect as it will not be able to find the correct banks.
- In FMOD Studio, go to Edit -> Preferences -> Assets. Add the keyword "LOCALE_" before the language code.
- For example, EN should become LOCALE_EN. Rename all the locales before performing the next step.
To use FMOD and its features, we need references to events, parameters, banks, buses and VCAs.
- Make sure to build the FMOD project and select the correct platform build directory before generating the FMOD Data.
- Go to Studio-23 -> Generate data from FMOD. This will generate data containing the references from FMOD Studio.
- You will need to generate the data again if you rebuild your FMOD project or if you want to build the Unity project for a different platform. Frequent regeneration will be needed as your project grows.
In the data generated you will find:
FMODBank_[BankName]
containing references to all the events under the[BankName]
Bank.FMODBankList
containing references to all the banks.FMODBusList
containing references to all the buses.FMODVCAList
containing references to all the VCAs.FMODParameterList
containing references to all the parameter names.FMODLocaleList
containing references to all languages supported by the current FMOD build and their corresponding bank.
Attach the FMODManager script to a GameObject in your scene. You can access the EventsManager, BanksManager and MixerManager through the FMODManager.
- The EventsManager can be used to play, pause, unpause, stop events. All events, game wide can be paused and unpaused. Programmer sounds can be played. Local and global parameters can be changed.
- Every sound is played through a Custom Studio Event Emitter. The only difference between our custom emitter and FMOD's emitter is in how the event instance is initialized.
- Sounds are not played through separate event intances.
- Sounds are not played through
PlayOneShot()
.
- Make sure the correct banks are loaded before playing a sound or creating an emitter, or else the sound won't play and will give you an error.
- Use
Play()
to play an event.- It will take the event we want to play and the gameobject from which it will play.
- By default, it will create an emitter on the GameObject and and its AllowFadeout is set to true.
- If the GameObject already has an emitter component, we can pass that emitter instead to initialize it. An Emitter can only be initialized once. So multiple Events will require multiple Emitters.
- If an emitter of type "event and GameObject" already exists, it will just play the event.
Pause()
,UnPause()
,Stop()
,Release()
,LoadEventSampleData()
, work similarly, but they need an emitter of type "event and GameObject" to exist or else they will do nothing.PlayAllOfType()
Plays all existing emitters of the same type of event. This does not create any emitters on its own.StopAllOfType()
andReleaseAllOfType
does not take in any GameObjects. They stop or release all emitters of the same event type.StopAll()
andReleaseAll
stop or release all existing emitters.- Sometimes an emitter may need to be created or initialized at runtime without playing it.
- Call
CreateEmitter()
to create an emitter on the GameObject. - It will take the event we want to play and the gameobject from which it will play.
- By default, it will create an emitter on the GameObject and and its AllowFadeout is set to true.
- If the GameObject already has an emitter component, we can pass that emitter instead to initialize it. An Emitter can only be initialized once. So multiple Events will require multiple Emitters.
- Once an emitter of type "event and GameObject" is created, we no longer have to create this emitter again to use playback methods.
- We can call playback methods on this emitter by passing in the event and the GameObject.
- Call
PlayProgrammerSound()
creates an emitter similar toPlay()
and plays the sound immediately.- It will take the key of the audio file we want to play, the event we want to play and the gameobject from which it will play.
- The key can be a key from a audio table from FMOD.
- The key can also be the file name of an audio file in the streaming assets folder.
- Do not call Stop when trying to stop Programmer sounds. Call Release instead.
LoadEventSampleData()
Loads the sample data of an event. It may be beneficial to load the sample data of an event that is frequently used, instead of loading/unloading every time the event is called.- Make sure to call
Release()
for events that are no longer needed. It will release the event instance and destroy the emitter. TogglePause()
will pause/unpause all the events in the game.SetLocalParameterByName()
is used to set a local parameter using its name for an event.- It will take the event, the gameobject from which it is playing, the parameter name and the parameter value.
SetLocalParameterAllOfTypeByName()
is used to set a local parameter using its name for all active instances of that event.SetGlobalParameter()
is used to set a global parameter value by name.GetLocalParameterValueByName()
andGetLocalParameterFinalValueByName()
is used to get the local parameter's current value and current final value respectively using its name.SetGlobalParameterByName()
andGetGlobalParameterValueByName()
is used to get the global parameter's current value and current final value respectively using its name.
- It can be attached to game objects as a component to play and manage events without the need for code.
- You need to assign the event you want to play and optionally one parameter that you would like to control.
- It also allows you to automate and ramp parameter changes for any event.
FadeIn()
,FadeInAllOfType()
,FadeOut()
,FadeOutAllOfType()
are used for fading in/out audio within a certain duration.- The event must have some parameter that controls the master volume of the event.
- Should not be used for ramping other parameters. May not work as expected.
- For the intended behavior,
startValue
should be set to0
andendValue
should be set to1
. - The bools
StopOnFadeOut
andReleaseOnFadeOut
can be marked as true to stop or release the event respectively after fading out. - Ideally these should not be true when ramping any other parameters other than volume. May not work as expected.
RampUpLocalParameter()
,RampUpLocalParameterAllOfType()
,RampDownLocalParameter()
,RampDownLocalParameterAllOfType()
are used to ramp up/down local parameters within a certain duration.- Should not be used for volume parameters or fading in/out. May not work as expected.
RampUpGlobalParameter()
,RampDownGlobalParameter()
, are used to ramp up/down global parameters within a certain duration.- The rest of the methods are similar to the methods in Events Manager.
- The BanksManager can be used to load/unload banks, load/unload sample data and switch localization. Make sure to load the correct banks before trying to play a sound.
LoadBank()
is used to load a bank. By default,LOAD_BANK_FLAGS
is set toNORMAL
.UnloadBank()
is used to unload bank. It cannot remove banks that have been specified FMOD in the FMOD Settings.UnloadAllBanks()
is used to unload all banks. It does not remove banks that have been specified FMOD in the FMOD Settings.LoadBankSampleData()
is used to load all the non-streaming sample data of a bank. Can also be used if banks are built with separate metadata and assets.SwitchLocalization()
is used to switch localization. It will unload the current localization bank and load the target localization bank.HasBankLoaded()
allows you to check if a specific bank has been loaded.HasAllBanksUnLoaded()
allows you to check if all banks have been unloaded. It does not check banks that have been specified FMOD in the FMOD Settings.
- It can be attached to game objects as a component to load/unload without the need for code.
- You need to assign the banks you want to load/unload.
LoadBank()
is used to load banks.UnloadBank()
is used to unload bank. It cannot remove banks that have been specified FMOD in the FMOD Settings.UnloadAllBanks()
is used to unload all banks. It does not remove banks that have been specified FMOD in the FMOD Settings.
- The MixerManager can be used to control the Buses and VCAs within FMOD.
SetBusVolume()
,PauseBus()
,MuteBus()
, all perform their respective functionality on the specified bus.StopAllBusEvents()
stops all events under a specific bus.SetVCAVolume()
is used to change the volume of a VCA.
This system uses two callback handlers.
- The default callback handler
FMODCallBackHandler
manages the internal playback states of each event (the internal states here refers to the internal states used by this package to keep track of which event is playing, suspended, paused or stopped or whether the event is looping; not FMOD's own playback states). This callback is set whenever an emitter is created and is fired with every event that is played. - The programmer callback handler
FMODProgrammerSoundCallBackHandler
manages the playback of externally loaded sounds and is required for dialogues and localized audio tables. This callback is set whenever anPlayProgrammerSound()
is called and is fired with every subsequent call. - It is possible to create and set your own callback handler. You can fetch or create an emitter using
CreateEmitter()
and pass this to the initialization method of your callback handler. Look at the initialization methods of our callback handle to get an idea on how to make your initialization method. Not using the the default callback handlerFMODCallBackHandler
will result in that events internal states not being tracked/handled.
- Open the FMOD Project file in the samples folder. Go to Files -> Build All Platforms.
- In Unity, go to FMOD -> Edit Settings.
- Under Bank Import, set Source Type to Single Platform Build and specify the Desktop build directory.
- Under Initialization, set Load Banks Specified.
- Under Specified Banks add
Master
,Master.strings
,Sample
, andDialogue
- Play the SampleScene.