Hi,
Thank you for sharing the code and detailed information.
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:
[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 in OnDestroy()
.
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.
In addition to your current method, you could also consider using a combination of Channel::setPosition and 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
Hope this helps, let me know if you have questions!