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 
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.
2 Likes
Hi,
Thank you for bringing this to our attention and sharing your workaround.
Unfortunately, I was not able to reproduce the issues in 2.03.
Could I grab some info:
- What version of the FMOD integration are you using?
- Could I grab a code snippet of how you are setting the delay on the events and triggering the event emitter?
- Could I get a screenshot of the events in your FMOD Studio project.
Hey, the integration version is 2.02.20.
This is the method I mostly use to schedule event instances to play.
void ScheduleEventInstance(FMOD.Studio.EventInstance eventInstance, ulong startDelay, ulong endDelay, bool stop)
{
if (eventInstance.getChannelGroup(out FMOD.ChannelGroup cg) == FMOD.RESULT.OK)
{
cg.getDSPClock(out ulong d, out ulong pd);
ulong s = pd + startDelay;
ulong e = pd + endDelay;
cg.setDelay(s, e, stop);
eventInstance.start();
}
}
The instances are created with FMOD.Studio.EventInstance instance = FMODUnity.RuntimeManager.CreateInstance(eventRef);
. And then released using that method I provided in my initial post.
Here’s a screenshot of an event that is one of the scheduled.
Just as an update, after testing a bit more, removing the:
if (e.getChannelGroup(out FMOD.ChannelGroup cg) == FMOD.RESULT.OK) cg.setDelay(0, 0, false);
seemed to work just fine, maybe I was previously releasing them wrong or something but looking at profiler the instance amounts of those scheduled sounds are now dropping to 0 (correctly) when they are released without the setDelay method.
1 Like
Thanks for sharing the info!