Since this is new and hard to come across good materials to get started, I thought I’d help the cause.
My main information sources were this: http://perttuh.blogspot.com/2013/10/unity-and-fmod-integration.html?showComment=1390266431189#c4026099878662781051 and this http://www.fmod.org/forum/viewtopic.php?f=30&t=18649. Much of this post will be directly pulled from these resources, but updated and with combined info.
The main reason to use this is that it enables your sound designers to edit, mix and master your game audio using the FMOD Studio interface WHILE THE GAME IS RUNNING. Don’t like that footstep sound? You can change it in REAL TIME while the game is running without recompiling or rebuilding.
- Import the fmodstudio.unitypackage from the fmod.org downloads section. To import in Unity editor, select Assets/Import Package/Custom package.
- Build your FMOD banks (File/Build), and export your GUIDs (you will have to do this everytime you create/delete an event)
- In Unity, select FMOD/Refresh Event List and select the GUIDs.txt from your FMOD project’s Build folder. Note: you need to do this whenever you rebuild the FMOD project and GUIDs. This will create FMODAssets and StreamingAssets folders in the Unity project and copy the FMOD banks to the StreamingAssets folder.
- When your scene starts, load a bank (see example below)
- Play a sound in through your Unity script (again, see example below). You might also have to sometimes use the lower level API (fmod.cs, fmodstudio.cs), as the unity integration package has been released very recently.
- To enable live mixing using FMOD Studio, uncomment the first line of FMOD_StudioSystem.cs, found in the plugins/FMOD folder. Also check the “Run in background” checkbox in Unity Editor, which can be found by selecting Edit/project settings/player and then selecting the Resolution and Presentation panel in the Inspector. Now press play in unity, select File/Connect to game in FMOD Studio and click ok. You can now adjust audio event properties on the fly while the game is running.
My example has a long sound event in the “Master Bank” called “zoomer” with a parameter called “zim” that changes the pitch:
using UnityEngine;
using System.Collections;
using FMOD.Studio;
public class sound : MonoBehaviour {
FMOD_StudioSystem soundSystem;
FMOD.Studio.EventInstance zoom;
FMOD.Studio.ParameterInstance pitch;
float pos = 0;
// Use this for initialization
void Start () {
//Cache the FMOD_StudioSystem instance for easier access
soundSystem = FMOD_StudioSystem.instance;
//declare a string variable holding the file name. The Application.dataPath is needed so that
//the sounds work both in the editor and in standalone builds
string fileName = Application.dataPath + "/StreamingAssets/Master Bank.bank";
//Load the FMOD bank
FMOD.Studio.Bank bank;
FMOD_StudioSystem.ERRCHECK(soundSystem.System.loadBankFile(fileName, out bank));
//Also load the corresponding strings bank so that we can find the events by their names
FMOD.Studio.Bank bankStrings;
FMOD_StudioSystem.ERRCHECK(soundSystem.System.loadBankFile(fileName + ".strings", out bankStrings));
zoom = soundSystem.getEvent("/zoomer");
zoom.getParameter("zim", out pitch);
zoom.start();
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
if (GUI.Button(new Rect(100,100,200,30),"Modify sound"))
{
//soundSystem.PlayOneShot("/boo",Vector3.zero);
pos += .1F;
pitch.setValue(pos);
}
}
}
Attach that script to your main camera.
Now, everytime you click the GUI button, you’ll hear your parameter changing live during playback (assuming you made a parameter called “zim” on the event “zoomer” that does something). And you can also change anything about this sound while its running if you are “connected” from FMOD Studio.
Again, most of this isn’t my original information, but it’s really hard to find a good example of these things right now because this stuff is so new.
This stuff is a total game-changer for video game sound design. THANK YOU FMOD AND UNITY! I can’t wait to see these features grow.