Releasing scheduled (setDelay) event instances

Just stumbled upon something interesting while testing our game’s build.
Audio started stuttering after playing for a while and some events just did not play at all.

I started profiling and I noticed that some event instances that should’ve been released kept stacking up in numbers over time.

The reason for this was that those event instances were “scheduled” using the ChannelGroup.setDelay method. This made is so that just calling eventInstance.stop(...IMMEDIATE) and eventInstance.release() was not enough. What I had to do was that I had to call channelGroup.setDelay(0,0,false) first!

I made this utility method in case it’s helpful for anyone :slight_smile:

public static void ReleaseScheduledInstance(FMOD.Studio.EventInstance e)
{
    if (!e.isValid()) return;

    if (e.getChannelGroup(out FMOD.ChannelGroup cg) == FMOD.RESULT.OK) cg.setDelay(0, 0, false);

    e.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
    e.release();
}

Additionally, I noticed that if you AddComponent<StudioEventEmitter>() and don’t set the emitter.StopEvent to be anything, they don’t seem to be released correctly either? After setting emitter.StopEvent = EmitterGameEvent.ObjectDestroy these “spawned” emitter’s instances did not stack up anymore.

1 Like