# XCode error on beat callback

**URL:** <https://qa.fmod.com/t/xcode-error-on-beat-callback/12723>\
**Category:** Unity\
**Created:** [September 30, 2016, 2:40pm UTC](https://qa.fmod.com/t/xcode-error-on-beat-callback/12723 "2016-09-30T14:40:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativeheroes](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@creativeheroes](https://qa.fmod.com/u/creativeheroes)\
**Post date:** [September 30, 2016, 2:40pm UTC](https://qa.fmod.com/t/xcode-error-on-beat-callback/12723/1 "2016-09-30T14:40:19Z")

</div>

Hi FMOD,

I’m having an issue when using the FMOD callback function for iOS. I get the following error:

_Unhandled Exception: System.NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code.  
at FMOD.Studio.EventInstance.setCallback (FMOD.Studio.EVENT\_CALLBACK callback, EVENT\_CALLBACK\_TYPE callbackmask) [0x00000] in :0  
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)  
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)_

The code used in Unity (JS) is as follows and works fine in Unity Editor:  
var cb: FMOD.Studio.EVENT\_CALLBACK;

[…]

cb = FMOD.Studio.EVENT\_CALLBACK(StudioEventCallback);  
SlitScore.setCallback(cb, FMOD.Studio.EVENT\_CALLBACK\_TYPE.TIMELINE\_BEAT);

[…]

function StudioEventCallback()  
{  
// do something  
}

Any idea?  
Sander

---

<div class="post-metadata">

**Author:** ![creativeheroes](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@creativeheroes](https://qa.fmod.com/u/creativeheroes)\
**Post date:** [September 30, 2016, 2:41pm UTC](https://qa.fmod.com/t/xcode-error-on-beat-callback/12723/2 "2016-09-30T14:41:03Z")

</div>

> [@](#):
>
> Hi FMOD,
> 
> I’m having an issue when using the FMOD callback function for iOS. I get the following error:
> 
> _Unhandled Exception: System.NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code.  
> at FMOD.Studio.EventInstance.setCallback (FMOD.Studio.EVENT\_CALLBACK callback, EVENT\_CALLBACK\_TYPE callbackmask) [0x00000] in :0  
> UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)  
> UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)_
> 
> The code used in Unity (JS) is as follows and works fine in Unity Editor:  
> var cb: FMOD.Studio.EVENT\_CALLBACK;
> 
> […]
> 
> cb = FMOD.Studio.EVENT\_CALLBACK(StudioEventCallback);  
> SlitScore.setCallback(cb, FMOD.Studio.EVENT\_CALLBACK\_TYPE.TIMELINE\_BEAT);
> 
> […]
> 
> function StudioEventCallback()  
> {  
> // do something  
> }
> 
> Any idea?  
> Sander

I used the latest integration SDK for Unity BTW.

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [October 2, 2016, 11:52pm UTC](https://qa.fmod.com/t/xcode-error-on-beat-callback/12723/3 "2016-10-02T23:52:54Z")

</div>

As the error message says, delegates can’t be instance methods. This is limitation on platforms that use IL2CPP or non-JIT mono.

Use a static method instead (see this Unity tutorial [https://unity3d.com/learn/tutorials/topics/scripting/statics](https://unity3d.com/learn/tutorials/topics/scripting/statics))

Our example of a beat callback shows a static method (written in C# though) [http://www.fmod.org/documentation/#content/generated/engine\_new\_unity/script\_example\_timeline.html](http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_timeline.html)
