Archive for May 2015

Getting Started with FMOD Unity Integration (Blok3)

Download

Download FMOD Studio and Studio Integration. Install Studio and import the package in Unity.

There are FMOD studio Projects (examples) in the FMOD Studio application folder.

Integration

FMOD studio integration manual (the manual)

Horse Awesome Game’ FMOD and Unity (the simple example created during the lesson, contains both Unity and FMOD Studio). This is JavaScript code, if your game programmer works in C# it is best to use C# code.

For C# examples, see the Example Scripts in the FMOD folder in the integration package. Refer to the manual, section Contents / Example Scripts for a description. The example scripts are named FMODAsset, FMOD_Listener, FMOD_StudioSystem and FMOD_StudioEventEmitter. With these sample scripts, you’re ready to go.

FMOD

Again, use the SAME versions of FMOD Studio and FMOD Integration. Make sure your game programmer does the same. If not, you might get crazy amounts of errors in Unity. You might ask why I’m repeating myself over and over on this, but I’ve seen this happening over and over again.
If there are crazy amounts of errors, ask you programmer to double check the version.

During the lesson I showed:

  1. Create an Event
  2. Import Sounds into
  3. Create a Multi Sound
  4. Assign the event to a bank before building
  5. Building
  6. Export GUIDs

Remember:

  • Play percentage (right click sounds in multi sound)
  • Random value via add modulation (right click volume or pitch)
  • Seek Speed

Great tutorials to get started are all over YouTube. This playlist is rather complete:

Unity

After importing the package you’ll get an FMOD tab in Unity (menu at the top of the screen).

Import banks om het FMOD project te importeren en selecteer de folder Build in je FMOD-project.

Play music with a parameter (JS)

For C#, see FMOD_StudioSystem.cs in the Unity folder.

 

// Place at the top of a script

var Music : FMOD.Studio.EventInstance;

var Intensity : FMOD.Studio.ParameterInstance;

// Place in Awake and change the GUID-code (in GUIDs txt in your build folder).

Music = FMOD_StudioSystem.instance.GetEvent(“{ba0fe66d-901b-415b-b672-e360a8b6cddc}”);

Music.getParameter(“Intensity”, Intensity);

{

Debug.LogError(“Awe parameter not found on music event”);

return;

}

// start music

Music.start();

// Pass the parameter – somewhere in a function, e.g. Update() or OnCollisionExit()

Intensity.setValue(0.0);

Intensity.setValue(0.28);

Intensity.setValue(1.0);

Play in C#

using UnityEngine;
using System.Collections;

public class RobotSound : MonoBehaviour {

//looping sound with a parameter
FMOD.Studio.EventInstance walkingSound;
FMOD.Studio.ParameterInstance speed;

//oneShot + “initiation”
string deathExplode = “event:/enemies/explodeSmall”;

//initialise looping sound
void Start()
{
walkingSound = FMOD_StudioSystem.instance.GetEvent(“event:/enemies/movingSmall”);
walkingSound.getParameter(“parameterNameinFMOD”, out speed);
}

//Start and stop looping sound
void startWalking()
{
walkingSound.start();
}
void stopWalking()
{
walkingSound.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
//OR
walkingSound.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
}

//oneShots start
void playExposion()
{
FMOD_StudioSystem.instance.PlayOneShot(deathExplode, transform.position);
}

//cleanup EventInstance, PlayOneShot() does not need this
//stop audio before cleanup!
void onDeath_or_Delete()
{
walkingSound.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
walkingSound.release();
}
}

Questions?

If there’s anything wrong, check/search the FMOD/Unity forum:
http://www.fmod.org/forum/viewforum.php?f=30

If there’s something really wrong and buggy, you could ask the developers at the FMOD in Unity questions section:
http://www.fmod.org/questions/categories/unity
You might have to wait for several days, especially over the weekend, so don’t rely on this when you have a deadline!

You could also email me. Just do it if you dare. 😀

Pitfalls

FMOD Studio has bugs. A lot of them. Fortunately, these are constantly being fixed, which is a good thing. That is why it’s tempting to update Studio and Unity Integration. Beware that new versions could introduce new issues with other code and libraries. FMOD projects are not necessarily backwards compatible, so you might make a copy first before upgrading your project.

Make backups. Make Backups. Make Backups! Make Backups! Just zip your FMOD project folder every now and then. I’ve completely destroyed an FMOD Studio project by opening it on a PC first and then on a Mac. FMOD support was willing to assist me on recovering the project but I was happy to restore a backup which opened fine.

“Being too busy to worry about backup is like being too busy driving a car to put on a seatbelt.” — T.E. Ronneberg