# Can i set EventInstance Callback with Class::Function?

**URL:** <https://qa.fmod.com/t/can-i-set-eventinstance-callback-with-class-function/19620>\
**Category:** FMOD Studio\
**Tags:** ue4\
**Created:** [December 6, 2022, 6:34am UTC](https://qa.fmod.com/t/can-i-set-eventinstance-callback-with-class-function/19620 "2022-12-06T06:34:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pigeon55](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@pigeon55](https://qa.fmod.com/u/pigeon55)\
**Post date:** [December 6, 2022, 6:34am UTC](https://qa.fmod.com/t/can-i-set-eventinstance-callback-with-class-function/19620/1 "2022-12-06T06:34:06Z")

</div>

I store some eventinstance when a event is played and I want remove them from TMap when the instance is destored.  
I found EventInstance::setCallback() function, but it cannot use like this:  
`instance->setCallback(CLASS::FUNCTION, FMOD_STUDIO_EVENT_CALLBACK_TYPE);`  
even though this CLASS::FUNCTION 's type is  
`FMOD_RESULT (F_CALLBACK *FMOD_STUDIO_EVENT_CALLBACK) (FMOD_STUDIO_EVENT_CALLBACK_TYPE type, FMOD_STUDIO_EVENTINSTANCE *event, void *parameters);`  
Is there any way i can bind a class function with a eventinstance callback?  
Thank you.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [December 13, 2022, 3:45am UTC](https://qa.fmod.com/t/can-i-set-eventinstance-callback-with-class-function/19620/2 "2022-12-13T03:45:18Z")

</div>

In order to set a function as a callback, it needs to be a non-member function, or a static member function. However, instead of setting a static member function as a callback to access your TMap, I’d recommend instead passing a pointer to your TMap to the event instance as user data by using [`Studio::EventInstance::setUserData`](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_setuserdata), and then retrieving it in the callback using [`Studio::EventInstance::getUserData`](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_getuserdata).

Hope that helps!

---

<div class="post-metadata">

**Author:** ![pigeon55](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@pigeon55](https://qa.fmod.com/u/pigeon55)\
**Post date:** [December 13, 2022, 6:36am UTC](https://qa.fmod.com/t/can-i-set-eventinstance-callback-with-class-function/19620/3 "2022-12-13T06:36:25Z")

</div>

Thank you for your help.  
Cause I store this map in lua and it’s a little trouble getting Key by value, so I decide use a timer to check it.  
Anyway thank you for your help.  
If my method is apperance bad, I will think what you said.
