# Unity editor crashes after playing multiple clips repeatedly

**URL:** https://qa.fmod.com/t/unity-editor-crashes-after-playing-multiple-clips-repeatedly/22791
**Category:** Unity
**Tags:** unity, csharp
**Created:** [April 12, 2025, 9:06am UTC](https://qa.fmod.com/t/unity-editor-crashes-after-playing-multiple-clips-repeatedly/22791 "2025-04-12T09:06:38Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![li\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/li_fmod/32/6577_2.png) [@li\_fmod](https://qa.fmod.com/u/li_fmod)
#### Post date: [April 15, 2025, 4:45am UTC](https://qa.fmod.com/t/unity-editor-crashes-after-playing-multiple-clips-repeatedly/22791/2 "2025-04-15T04:45:50Z")

</div>

Hi,

Thank you for sharing the code and detailed information.

> [@thehighestend](#):
>
> What should I do to run my program stably, without the crash?

From the code you provided, it looks like the `ChannelStopCallback` is not marked as static. To avoid crashes, you will need to make the callback static and decorate it with the `[AOT.MonoPInvokeCallback(typeof(FMOD.CHANNELCONTROL_CALLBACK))]` attribute.

For example:

```auto
    [AOT.MonoPInvokeCallback(typeof(CHANNELCONTROL_CALLBACK))]
    static RESULT ChannelStopCallback(IntPtr channelcontrol, CHANNELCONTROL_TYPE controltype,
        CHANNELCONTROL_CALLBACK_TYPE callbacktype, IntPtr commanddata1, IntPtr commanddata2)
    {
        if (callbacktype == CHANNELCONTROL_CALLBACK_TYPE.SYNCPOINT)
        {
            var channel = new Channel(channelcontrol);
            channel.setVolume(0f);
        }

        return RESULT.OK;
    }

```

Also, for calling [System::release](https://www.fmod.com/docs/2.00/api/core-api-system.html#system_release) in `OnDestroy()`.

```auto
    private void OnDestroy()
    {
        FMODUnity.RuntimeManager.CoreSystem.release();
    }

```

That line is likely contributing to the crash as well since FMOD handles system teardown automatically, so you might need to remove that call.

> [@thehighestend](#):
>
> This question is optional, but is there a way to create certain channels and limit playbacks within the range? I tried adding a channel group to the master channel but I’m not sure if it’s the right way.

In addition to your current method, you could also consider using a combination of [Channel::setPosition](https://www.fmod.com/docs/2.02/api/core-api-channel.html#channel_setposition) and [ChannelControl::setDelay](https://www.fmod.com/docs/2.02/api/core-api-channelcontrol.html#channelcontrol_setdelay) to control playback timing more precisely.

There’s also a helpful discussion on a similar topic here: [Playing sound specific range - #9 by jeff\_fmod](https://qa.fmod.com/t/playing-sound-specific-range/18497/9)

Hope this helps, let me know if you have questions!

---

_[View the full topic](https://qa.fmod.com/t/unity-editor-crashes-after-playing-multiple-clips-repeatedly/22791)._
