Unity Integration Basics

Hey there everyone! I am quite familiar with FMOD studio, and I’ve recently been learning Unity to make an audio showcase. I downloaded the Fmod Studio Unity package and imported it into my Unity Project. Just from poking around, I was able to figure out some basic stuff. I create FMOD Assets by refreshing from the GUIDs list. I added the Listener script to my player. I added an Emitter playing a loop to test out 3D audio. All easy stuff once I figured it out.

But this only gets me a recreation of the functionality already built into Unity - listeners and positional audio - just from my actual Studio build instead of using Unity components.

I can’t figure out how to to take it to the next level with scripting. I imagine in scripts, there’s a way to set parameter values and all that cool fancy stuff. I am familiar with code in general, I just can’t figure out what the API calls are, how to reference the right Event, etc…

I can’t find actual documentation on it anywhere. Any help would be greatly appreciated!

I am relatively new to Fmod Studio and programming in general. This is the first time I have tried integrating Fmod into unity. I have successfully loaded Fmod into unity and played a sound through an event emitter just as ambience. Now I am trying to play an event as my player object moves through my level. This is my current code:

using UnityEngine;
using System.Collections;
using FMOD.Studio;


public class PlayerMovement : MonoBehaviour {
	public float moveSpeed;
	public GameObject deathParticles;
	private float maxSpeed = 5f;
	public float timer;
	private Vector3 input;
	private Vector3 spawn;
	public bool isDead;
	public float RotateSpeed = 30f;
	FMOD.Studio.EventInstance playermove;
	FMOD.Studio.ParameterInstance speed = 0f;



	// Use this for initialization
	void Start () {
		timer = 0.0f;
		isDead = false;
		spawn = transform.position;
		rigidbody.AddForce (0, 0.25f, 0, ForceMode.Impulse);
		playermove = FMOD_StudioSystem.instance.GetEvent("/Player/Player_Move");
		playermove.start ();
	}
		
	

	void Update () 
	{

			speed = moveSpeed;
		if (timer < 2 && isDead)
		{
			timer += Time.deltaTime;
		}
		if (isDead && timer > 2) 
		{
			isDead = false;
			transform.position = spawn;
			timer = 0.0f;
		}
		input = new Vector3(Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
		if(rigidbody.velocity.magnitude < maxSpeed)
		{
			rigidbody.AddRelativeForce(input * moveSpeed);		
		}

		if (transform.position.y < -2)
		{
			Die ();
		}
		if (Input.GetKey ("q")) 
		{
			transform.Rotate (-Vector3.up * RotateSpeed * Time.deltaTime);
		}

		else if (Input.GetKey ("e")) 
		{	
			transform.Rotate (Vector3.up * RotateSpeed * Time.deltaTime);
		}
	}

	void OnCollisionEnter(Collision other)
	{
		if (other.transform.tag == "Enemy")
		{
			isDead = true;
			Die ();

		}
	}

	void OnTriggerEnter(Collider other)
	{
		if (other.transform.tag == "Goal")
		{	
			GameManager.CompleteLevel();
			isDead = false;
		}
	} 


	void Die() 
	{
		Instantiate(deathParticles, transform.position, Quaternion.identity);
		transform.position = new Vector3(transform.position.x, -1, transform.position.z);
		isDead = true;



	}

  }

Im not sure if I have to load banks and what not, or even have an Fmod event emitter on my player object. Only error im getting right now is:
Assets/Scripts/PlayerMovement.cs(19,48): error CS0029: Cannot implicitly convert type float' toFMOD.Studio.ParameterInstance’

but it doesnt seem that unity is recognizing my Fmod.Studio input or anything associated with it.

it will work, but you cannot assign Events in FMOD Studio to anything except the MasterBank. it will not create the FMODAssets folder on initial import.

if you’re getting NullRefs in playing back the audio here’s the checklist i use:

  1. Sometimes, initially, there’s a huge raft of errors when you first start using the integration. weirdly enough, going to FMOD>About this Integration can help to cure a lot of these errors where it won’t even preview sounds in Unity Free. not sure why.

  2. Is the FMOD Listener on the Main Camera Object (or wherever your Unity Audio Listener is)? that’s a big and common one.

  3. Are you using the latest integration clean installed? i had issues updating older integrations in Unity and had to remove the older integration completely before it would work.

  4. Did you move your Unity project or FMOD project folder? seems the integration has issues with losing the path to the events when one source or the other has moved. i have had varying success with nuking the FMODAssets and StreamingAssets folders, and re-importing the Build from the original project. it’s tricky because the Bank file has the same GUID as the previous banks and it will tell you that you can’t re-import the same bank.

i’ve tried a number of methods to shake this but it’s not easy. the sure fire method is just to start all over from scratch with a new project (you can copy your Automation curves from your old project but not Events), but you may be able to edit the GUID in the Bank build file itself (NOTE - THIS IS A HACK - not recommended).

other fun things - if you accidentally open the FMOD Studio project in any version of FMOD Studio prior to 1.03.03 you risk permanently damaging your project and making it impossible to integrate without - you guessed it - starting from scratch. we had 1.02.12 installed on our school computers and opening any project in that would instantly make the integration break. so backup a ton if you’re integrating.

1 Like

For those of you having trouble with Unity auto-generating the FMODAssets folder after refreshing the event list, have you made sure to assign your events to a bank in FMOD? I didn’t realize at first that even for the MasterBank, you still have to manually assign your events to the MasterBank…

I have the exact same problem as benybody1. It creates the StreamingAssets folder with my banks inside, but doesn’t create a FMODAssets folder with my events. I have the current version of FMOD and the latest unity package (10306). I tried Pravusjif’s idea of copy and pasting manually, but this didn’t solve the issue.

If anyone could help, it would be greatly appreciated.

Thanks

Edit: So I’ve realised you have to have Unity Pro license in order to use FMOD, I guess that’s why it’s not working

I just tested it with Unity free and it appears to work and creates the FMOD Assets folder as expected. You cannot ship a games for PC/Mac/Desktop with the Unity free license because FMOD requires native plugin support which is only available in Pro. You should be able to use it inside the editor and for iOS and Android though.

Hey There was wondering if anyone could help,

I am having a problem with my integration.I just started using Unity for a university project to show audio implementation with FMOD - which I have never used before either. so I am a beginner in terms of scripting and everything else really. My main problem is after the intial integration. I build my banks and export my GUIDs in FMOD, and then refresh the event list in the FMOD menu in Unity, but this only creates bank files in a StreamingAssets folder and doesnt create a FMODAssets Folder with my events. Ive tried multiple times with different projects but its always the same, all I want is to be able to get audio to play. Any advice would be appreciated, thanks.

Hello benybody1 i’m having some trouble with integrating FMOD with unity too, and i just confirmed that to get the FMODAssets folder automatically created you have to manually copy the banks inside your FMOD project folder (inside the /build/ folder) and paste them inside your Assets/StreamingAssets/ folder in unity. after this if you just go to FMOD->Refresh Event List from the Unity Editor, the FMODAssets folder will be created with the corresponding files inside.

I’m having some trouble with the new version of the package. I switched my stuff over to have “event:/” in front of my event names and it no longer complains about that. I added an FMOD_Listener script to my main camera, but I still get 1 NULLReferenceException because I’m attempting to play something on Start(), and then as my game goes on, I don’t get any more NULLReferenceException, but no sound plays either. How can I fix these issues?
Thanks

I fixed my NULLReferenceException problem, something else had to change on my end, now, I’m getting a “These banks were built with an incompatible version of FMOD” error, both FMOD Studio and the FMOD Studio Unity package say 1.03.05 and even in the error says the current integration version is 1.03.05 but I’m still getting this error, even after rebuilding the banks.

It looks like it’s working in other scenes. all of the sounds in our game are 2D, so when we switch from scene to scene, and the camera has a different listener, it changes the volume of that sound. so during our game, our game is far away, so that’s why i wasn’t hearing anything. How do i get it to do 2D?

also only on the scene where I can’t hear anything, it keeps saying “ERR_FILE_NOTFOUND” which might have to do with the way our cameras are set up? I think we have 8, but one main camera, and the others are children of the main camera, and I put the listener on the main camera like in all the other scenes and it works fine in those.

EDIT: now it’s saying it can’t find any of the files in any of the scenes… and I didn’t even change anything. I can play the sounds from the FMODAssets folder just fine. every time I refresh the event list it moves the same 11 events even when it’s the same, I’m not sure if that’s normal or not

Hi DanjelRicci,

I’m also getting the NullReferenceException error - what exactly did you do to get that working?

EDIT: I’m SUCH an idiot. I kept missing the significance of ‘add the listener to the camera’, meaning go to Component->Scripts->FMOD Listener and add to the camera. I’d only added a Main script to the camera, and was confused because an ‘Audio Listener’ (not FMOD) was already attached to the camera.

Hello and thanks so much for the help!
I started using Fmod with Unity today but the script up there gives me some problems.
First I had to change engine = FMOD_StudioSystem.instance.getEvent("/Vehicles/Car Engine"); to engine = FMOD_StudioSystem.instance.getEvent(“event:/Vehicles/Car Engine”); to avoid an error Fmod wanting a “/” at the beginning of the path (and that’s weird because it already was present there).
But then, if I debug the “engine” variable, it rerturns Null, in fact I get a NullReferenceException error when trying to do engine.start().

Thanks for the help!

EDIT: Oh gosh, nevermind, now it’s working great. Only later I realized had to attach the listener to the camera… Makes sense. :lol:

Yes, best post in this topic for sure. Thanks so much!

Hi there,

We’re still in the process of creating examples and documentation for the integration. For the short term I recommend downloading the API installer and looking at the documentation and examples for the C++ API. The C# Studio API exposes the same features as the C++ API.

There are some extra convenience classes built on top which can be handy as well. For those I will provide a brief description here for you.

FMOD_StudioSystem - this is a singleton which can be used to create event instances.

PlayOneShot - play a finite event at a given position in the world and destroy the event when it completes. This is good for one off sound effects that don’t require parameter control.
getEvent - create an instance of an event. The FMOD.Studio.EventInstance returned can be controlled from script, start(), stop(), getParameter().

An example could be something like this:

FMOD.Studio.EventInstance engine;
FMOD.Studio.ParameterInstance engineRPM;

void Start()
{
    engine = FMOD_StudioSystem.instance.getEvent("/Vehicles/Car Engine");
    engine.start();
    engine.getParameter("RPM", out engineRPM);
}

void Update()
{
    // get a RPM value from the game's car engine
    engineRPM.setValue(rpm);
}

void OnDisable()
{
    engine.stop();
}

Thank you, this is super helpful, and good to hear that you’re also working on some official documentation and examples! Thanks so much for the continued support!

I have this, no errors, the print(result) prints ‘OK’, and still dont have any sound playing. (Double clicking the asset from the project folder plays the sound)

using UnityEngine; 
using System.Collections; 
public class play_Footsteps : MonoBehaviour 
{ 
FMOD_StudioSystem soundSystem;
FMOD.Studio.EventInstance evt;
FMOD.RESULT result;
void Start () 
{ 
	soundSystem=FMOD_StudioSystem.instance; 
	evt = FMOD_StudioSystem.instance.GetEvent("event:/Footsteps/FootSteps"); 
	result = evt.start ();
	print (result);
} 
// Update is called once per frame 
void Update () 
{
}
}

Hi Sid, it’s probably worthwhile to create a question for this issue. It doesn’t look like you have set the 3D attributes for the footstep event so it is probably playing at position (0,0,0) in the world, which could be a long distance from the listener making it play silently.

I’m having some trouble with the new version of the package. I’ve never seen the FMOD/Import in menu,I only see the FMOD/Refresh Banks. And I can’t Continue to my work…