# Callback each time a scatter instrument plays a new sound?

**URL:** <https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908>\
**Category:** FMOD Studio\
**Tags:** unity\
**Created:** [July 22, 2024, 7:42pm UTC](https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908 "2024-07-22T19:42:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deHaan](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/dehaan/32/68_2.png) [@deHaan](https://qa.fmod.com/u/deHaan)\
**Post date:** [July 22, 2024, 7:42pm UTC](https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908/1 "2024-07-22T19:42:26Z")

</div>

I’d like to use the playback from a scatter instrument to control stuff in our game (Unity). Is it possible to get a callback when the scatter instrument plays a new sound?

Thank you!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 23, 2024, 3:58am UTC](https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908/2 "2024-07-23T03:58:31Z")

</div>

Hi,

The event callback [FMOD\_STUDIO\_EVENT\_CALLBACK\_SOUND\_PLAYED](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_event_callback_type:~:text=FMOD_STUDIO_EVENT_CALLBACK_SOUND_PLAYED) will be triggered each time a new sound is played. We have an example setting up a callback in Unity here: [Unity Integration | Scripting Examples - Timeline Callbacks](https://fmod.com/docs/2.02/unity/examples-timeline-callbacks.html).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![deHaan](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/dehaan/32/68_2.png) [@deHaan](https://qa.fmod.com/u/deHaan)\
**Post date:** [July 23, 2024, 6:17am UTC](https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908/3 "2024-07-23T06:17:58Z")

</div>

Awesome, that sounds perfect!  
I don’t see and example of the SOUND\_PLAYED in that link though, am I missing something?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 23, 2024, 6:38am UTC](https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908/4 "2024-07-23T06:38:58Z")

</div>

> [@deHaan](#):
>
> I missing something?

No, the example just outlined how to set up the callback. Here is an example just for `SOUND_PLAYED`

```auto
public class ScatterInstrumentCallbacks : MonoBehaviour
{
    public FMODUnity.EventReference eventReference = new FMODUnity.EventReference();
    private FMOD.Studio.EventInstance eventInstance = new FMOD.Studio.EventInstance();
    private FMOD.Studio.EVENT_CALLBACK eventCallback = null;

    // Start is called before the first frame update
    void Start()
    {
        eventCallback = new FMOD.Studio.EVENT_CALLBACK(ScatterInstrumentCallback);

        eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventReference);
        if (eventInstance.isValid())
        {
            eventInstance.setCallback(eventCallback);
            eventInstance.start();
            eventInstance.release();
        }
    }

    [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
    static FMOD.RESULT ScatterInstrumentCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
    {
        switch (type)
        {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED:
                var sound = new FMOD.Sound(parameterPtr);
                sound.getName(out string name, 256);
                Debug.Log($"Sound Name {name}");
                break;
            default:
                break;
        }
        return FMOD.RESULT.OK;
    }
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![deHaan](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/dehaan/32/68_2.png) [@deHaan](https://qa.fmod.com/u/deHaan)\
**Post date:** [July 23, 2024, 7:22am UTC](https://qa.fmod.com/t/callback-each-time-a-scatter-instrument-plays-a-new-sound/21908/5 "2024-07-23T07:22:44Z")

</div>

Very helpful, thank you Connor!
