One Shot Events with automation parameters

Hello FMOD

I’m trying to start events as one shots and also control automation parameters.
From what you wrote on another topic it looks like I should get the event-instance, start and then release the instance.

I have a ball that bounces and I want the impact sound to play each time the ball hits the floor.

I wrote this (C#):

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

public class sphereTrigger : MonoBehaviour 
{
	FMOD.Studio.EventInstance oneShot;
	
	void Start () 
	{
		oneShot = FMOD_StudioSystem.instance.getEvent("event:/oneShot");
	}

	void OnCollisionEnter() 
	{
		oneShot.start();
		oneShot.release();

		print("bounce");
	}
}

Console is printing “bounce” each time the ball hits the floor, BUT the sound is only played the first time!

The event contains one event sound with default settings. Everything sounds as it should except the sound is only played once.

What am I missing?

Cheers,
Andreas

Hi Peter,

I’m having trouble with this script for launching 3D oneshot sounds. It works fine with 2D sounds but can’t launch 3D sounds. I’m having trouble finding any documentation on scripting 3D sounds using FMOD in Unity. Is there anyway you could give a few pointers? If anyone else has some tips for this please let me know!

Try to use getEvent everytime before you start the the event,
because once you release the event, the EventInstance is empty.


void OnCollisionEnter() 
   {
      oneShot = FMOD_StudioSystem.instance.getEvent("event:/oneShot");
      oneShot.start();
      oneShot.release();

      print("bounce");
   }

Does anyone know if there are any performance issues with geting & releasing events all the time…?

No there shouldn’t be any performance issues, that is the recommended method for firing off oneshot events. The release will make sure all the resources for the instance are cleaned up when the event finishes.