I’m struggling to understand how to manage the dialogue using callbacks. I searched for online resources to no avail and also tried random ideas to understand how to check for the callback type but I’m getting nowhere.
What I would like to achieve is - when an audio file from the programmer ends playing, I would like to play another sound, when that one ends, play another one. I’ve implemented an alternative using the multi instrument but with that I have no clear indication when a sound ends.
I’m assuming that I have to check for FMOD.Studio.EVENT_CALLBACK_TYPE in the Update() method and if it is equal to FMOD.Studio.EVENT_CALLBACK_TYPE.STOPPED, to trigger my next audio sample?
Also, I don’t understand where this callback is stored. Is it in
var dialogueInstance = FMODUnity.RuntimeManager.CreateInstance(“event:/World01/Prog”);
Or is it here -
dialogueCallback = new FMOD.Studio.EVENT_CALLBACK(DialogueEventCallback);
I saw that there is a setCallback() method that can be applied to dialogueInstance but I couldn’t understand how to get the callback.
The second one is the callback. An event instance is a playable instance of the event that you setup in FMOD Studio. A callback is a function with a specific signature that will be called at a time of the event’s choosing. You need to create this callback function yourself and assign the callback to the event instance with setCallback.
dialogueCallback = new FMOD.Studio.EVENT_CALLBACK(DialogueEventCallback);
And link it to the event instance:
dialogueInstance.setCallback(dialogueCallback);
Then you will be able to do things at different point in the event instance’s lifecycle.
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
switch (type)
{
case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
{
// Play a sound
break;
}
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
{
// Clean up the sound you made before
break;
}
FMOD.Studio.EVENT_CALLBACK_TYPE.STOPPED:
{
// The event is being stopped
break;
}
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
{
// The event is being destroyed
break;
}
}
return FMOD.RESULT.OK;
}