Know when an EventInstance has been released

Hi, I would like to know a way that I can ether receive a callback or know when an event has been released. I have marked the event for release when I play the event.

 public EventInstance Play(string clipName)
    {
        var instance = RuntimeManager.CreateInstance(GetEventID(clipName));
        instance.start();
        instance.release();
        if (EventInstances.ContainsKey(clipName) == true)
        {
            EventInstances[clipName] = instance;
        }
        else
        {
            EventInstances.Add(clipName, instance);
        }
        return instance;
    }

I want to know when it is being released so that i can remove it from my Dictionary EventInstances.
Or if i can get a callback when the audio is finished playing that will also be fine.

Cheers.

Hi,

You can indeed receive a callback when an event has finished playing after having been released. The callback type FMOD_STUDIO_EVENT_CALLBACK_TYPE.DESTROYED will trigger a callback specified by Studio.EventInstance.setCallback() when an instance is just about be destroyed. Passing your dictionary to the event instance as user data with Studio.EventInstance.setUserData(), and retrieving it with Studio.EventInstance.getUserData(), will allow you to remove the instance from the dictionary within the callback.

Thanks @Leah_FMOD,
I was able to get this to work with EVENT_CALLBACK. But I just send my key for the Dictionary instead of the whole Dictionary.
For Future Refence here is my Solution

 public EventInstance Play(string clipName)
    {
        var instance = RuntimeManager.CreateInstance(GetEventPath(clipName));
        instance.setUserData(GCHandle.ToIntPtr(GCHandle.Alloc(clipName)));
        instance.setCallback(eventReleasedCallback, EVENT_CALLBACK_TYPE.DESTROYED);
        instance.start();
        instance.release();
        EventInstances.Add(clipName, instance);
        return instance;
    }
 [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
    private RESULT OnInstanceDestroyed(EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameters)
    {
        var instance = new FMOD.Studio.EventInstance(instancePtr);
        instance.getUserData(out var userData);
        var clipName = GCHandle.FromIntPtr(userData).Target as string;
        EventInstances.Remove(clipName);
        return RESULT.OK;
    }