# About callback and Upgrade

**URL:** <https://qa.fmod.com/t/about-callback-and-upgrade/14710>\
**Category:** Unity\
**Created:** [May 23, 2019, 2:53am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710 "2019-05-23T02:53:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Katrol](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Katrol](https://qa.fmod.com/u/Katrol)\
**Post date:** [May 23, 2019, 2:53am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/1 "2019-05-23T02:53:32Z")

</div>

Is this a correct way to do that I need to check instance’s state in RuntimeManager.cs update function,so I should add some code in fmod plugins.But Once I upgrade the project(like 1.0 to 2.0),the additional work is to check these files to merge,and why do you not add these functions such like “SetSoundCallBack” function in internal project?

---

<div class="post-metadata">

**Author:** ![Katrol](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Katrol](https://qa.fmod.com/u/Katrol)\
**Post date:** [May 23, 2019, 4:03am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/2 "2019-05-23T04:03:19Z")

</div>

To achieve my logic code separate from plugins project ,I do these work.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/1X/1c8c01744c9efaf1f33e5bff8561139d1bf70ff9.png) This is startup work.  
[https://drive.google.com/open?id=10s407WLZczlDtrONcRqozh4\_i2NFVvXs](https://drive.google.com/open?id=10s407WLZczlDtrONcRqozh4_i2NFVvXs) This is “CallBack” code according to “timeline” example.But I’m doubt about it that AudioManager.cs and RuntimeManager.cs update() funtion’s order,RuntimeManager might run first and delete instance,so AudioManager didn’t receive correct callback.But it woks well.So is there correct work?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Katrol](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Katrol](https://qa.fmod.com/u/Katrol)\
**Post date:** [May 24, 2019, 7:47am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/3 "2019-05-24T07:47:23Z")

</div>

I wonder that set sound callback and when it’s called, change finished state,so I can check state in Update().Because callback is from another thread,otherwise I need to check state in RuntimeManager’s update. This work is in a global manange script.Is it acceptable as I don’t want change RuntimeManager.cs? I want some suggestions ~~

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [May 27, 2019, 5:43am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/4 "2019-05-27T05:43:51Z")

</div>

> [@Katrol](#):
>
> Is this a correct way to do that I need to check instance’s state

You can check an Instances state using [`EventInstance::getPlaybackState`](https://fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventinstance.html#studio_eventinstance_getplaybackstate), or by using the [`FMOD_STUDIO_EVENT_CALLBACK_STOPPED`](https://fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventinstance.html#fmod_studio_event_callback_type) callback.

> [@Katrol](#):
>
> why do you not add these functions such like “SetSoundCallBack” function in internal project?

I’m not sure what you mean by this, there is a [`EventDescription::setCallback`](https://fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventdescription.html#studio_eventdescription_setcallback) which will be assigned to all event instances subsequently created from the event.

> [@Katrol](#):
>
> But I’m doubt about it that AudioManager.cs and RuntimeManager.cs update() funtion’s order

You can specify/change [script execution order](https://docs.unity3d.com/Manual/class-MonoManager.html) in Unity.

---

<div class="post-metadata">

**Author:** ![Katrol](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Katrol](https://qa.fmod.com/u/Katrol)\
**Post date:** [May 27, 2019, 6:32am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/5 "2019-05-27T06:32:59Z")

</div>

Perhaps,I don’t think you understand what I say.

At the beginning, I do use EventInstance::getPlaybackState, it need that I add some code in RuntimeManager.cs.Of course,it works.But when next upgrade,I need to merge these changes like  
RuntimeManager.

After that,I use EventDescription::setCallback,but it works in another thread,not in unity’s main thread.  
However,I can change some parameters like you do in the Timeline example but it can not excute your delegate directly.And then I try to excute the delegate when I check the parameter’s change in the scrpt’s Update() function.It works too,so I ask that Is it also a right way ?

About script execution odrer in Unity,I know this.And I also let RuntimeManager.cs later then default script like that.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [May 28, 2019, 3:40am UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/6 "2019-05-28T03:40:33Z")

</div>

There shouldn’t be any race conditions that you need to worry about, our callbacks should execute on the same thread that calls RuntimeManager::update.

It doesn’t sound ideal to use a callback to set a bool on an object so that you can poll the object in Update later. You should be able to trigger your action from the sound stopped callback.

---

<div class="post-metadata">

**Author:** ![Katrol](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Katrol](https://qa.fmod.com/u/Katrol)\
**Post date:** [May 28, 2019, 12:36pm UTC](https://qa.fmod.com/t/about-callback-and-upgrade/14710/7 "2019-05-28T12:36:55Z")

</div>

OK，thanks for your reply
