I’d like to use the playback from a scatter instrument to control stuff in our game (Unity). Is it possible to get a callback when the scatter instrument plays a new sound?
Thank you!
I’d like to use the playback from a scatter instrument to control stuff in our game (Unity). Is it possible to get a callback when the scatter instrument plays a new sound?
Thank you!
Hi,
The event callback FMOD_STUDIO_EVENT_CALLBACK_SOUND_PLAYED will be triggered each time a new sound is played. We have an example setting up a callback in Unity here: Unity Integration | Scripting Examples - Timeline Callbacks.
Hope this helps!
Awesome, that sounds perfect!
I don’t see and example of the SOUND_PLAYED in that link though, am I missing something?
No, the example just outlined how to set up the callback. Here is an example just for SOUND_PLAYED
public class ScatterInstrumentCallbacks : MonoBehaviour
{
public FMODUnity.EventReference eventReference = new FMODUnity.EventReference();
private FMOD.Studio.EventInstance eventInstance = new FMOD.Studio.EventInstance();
private FMOD.Studio.EVENT_CALLBACK eventCallback = null;
// Start is called before the first frame update
void Start()
{
eventCallback = new FMOD.Studio.EVENT_CALLBACK(ScatterInstrumentCallback);
eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventReference);
if (eventInstance.isValid())
{
eventInstance.setCallback(eventCallback);
eventInstance.start();
eventInstance.release();
}
}
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT ScatterInstrumentCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
switch (type)
{
case FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED:
var sound = new FMOD.Sound(parameterPtr);
sound.getName(out string name, 256);
Debug.Log($"Sound Name {name}");
break;
default:
break;
}
return FMOD.RESULT.OK;
}
}
Hope this helps!
Very helpful, thank you Connor!