# Using EventInstance captured from START\_EVENT\_COMMAND callback

**URL:** <https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [October 12, 2021, 4:39pm UTC](https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785 "2021-10-12T16:39:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hscharfetter](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@hscharfetter](https://qa.fmod.com/u/hscharfetter)\
**Post date:** [October 12, 2021, 4:39pm UTC](https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785/1 "2021-10-12T16:39:15Z")

</div>

Hello,

I am trying to get an event instance from a START\_EVENT\_COMMAND callback and then use it later on in managed code to update params/attach it to a transform.  
The callback seems to work without complaint, but I’m getting an assert when trying to get the description of this event instance later on:

```auto
[FMOD] assert : assertion: 'inst->mHandleBits != 0' failed

```

Here is how my callback looks:

```auto
[AOT.MonoPInvokeCallback(typeof(EVENT_CALLBACK))]
		static RESULT HandleCallback(EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
		{
			FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
            IntPtr callbackInfoPtr;
            FMOD.RESULT result = instance.getUserData(out callbackInfoPtr);

            if (result != FMOD.RESULT.OK)
            {
                UnityEngine.Debug.LogError("FMOD Callback error: " + result);
                return result;
            }
            else if(callbackInfoPtr != IntPtr.Zero)
            {
                GCHandle callbackHandle = GCHandle.FromIntPtr(callbackInfoPtr);
                StartEventData callbackInfo = (StartEventData)callbackHandle.Target;

                switch (type)
                {
                    case FMOD.Studio.EVENT_CALLBACK_TYPE.START_EVENT_COMMAND:
                        {
                            if(parameterPtr != IntPtr.Zero)
							{
                                try
								{                   
                                    FMOD.Studio.EventInstance param = new FMOD.Studio.EventInstance(parameterPtr);
                                    if(param.isValid() && param.hasHandle())
									{
                                        callbackInfo.Triggered = 1;
                                        callbackInfo.StartedInstance = new EventInstance(parameterPtr);
									}
								}
                                catch(Exception e)
								{
                                    UnityEngine.Debug.Log(e);
								}
							}
                        }
                        break;
                    default:
                        break;
                }
            }
            return FMOD.RESULT.OK;
		}

```

And here is the call where I get the assert (this happens later down the line in a monobehaviour update where I wait for the “Triggered” to be set to 1):

```auto
ignitionCallback.Data.StartedInstance.getDescription(out var desc);

```

What am I doing wrong? Or is there a different way I should go about updating an instance that was started this way?  
If needed I can provide more code than this.  
Also, interestingly, using the runtime manager to attach this instance to a gameobject does not produce any errors.

Thank you.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [October 17, 2021, 11:44pm UTC](https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785/2 "2021-10-17T23:44:41Z")

</div>

I think I might need a little more context to figure out what’s going on here- can you please share a code snippet for what’s happening when you call `setCallback`?

---

<div class="post-metadata">

**Author:** ![hscharfetter](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@hscharfetter](https://qa.fmod.com/u/hscharfetter)\
**Post date:** [October 18, 2021, 8:31am UTC](https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785/3 "2021-10-18T08:31:10Z")

</div>

Sure,

the callback is wrapped in a class and set when that class is constructed, like so:

```auto
		public FMODStartEventCallback(EventInstance eventInstance)
		{
            data = new StartEventData();
            callbackHandle = GCHandle.Alloc(data, GCHandleType.Pinned);

			actualCallback = new FMOD.Studio.EVENT_CALLBACK(HandleCallback);
			eventInstance.setUserData(GCHandle.ToIntPtr(callbackHandle));
            eventInstance.setCallback(actualCallback, EVENT_CALLBACK_TYPE.START_EVENT_COMMAND);
		}

```

Another class then later asks this wrapper class for the data from the callback, which is defined like this:

```auto
    [StructLayout(LayoutKind.Sequential)]
    public class StartEventData
	{
		public EventInstance StartedInstance;
        public int Triggered;
	}

```

the returned EventInstance also returns true on isValid and hasHandle, but trying to get the description fails as mentioned above.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [October 19, 2021, 4:53am UTC](https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785/4 "2021-10-19T04:53:05Z")

</div>

Thanks for the extra info- it seems there is a problem with the underlying API and the START\_EVENT\_COMMAND callback isn’t returning a valid handle to the new EventInstance, even though `isValid` and `hasHandle` are both somehow returning true.  
I’ve written up a bug report for the dev team to look into.

---

<div class="post-metadata">

**Author:** ![hscharfetter](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@hscharfetter](https://qa.fmod.com/u/hscharfetter)\
**Post date:** [October 20, 2021, 3:35pm UTC](https://qa.fmod.com/t/using-eventinstance-captured-from-start-event-command-callback/17785/5 "2021-10-20T15:35:35Z")

</div>

Thanks for looking into it!  
We’ll try to work around the issue for now.
