# Identify sound played within Scatterer Sound

**URL:** https://qa.fmod.com/t/identify-sound-played-within-scatterer-sound/13165
**Category:** Unity
**Created:** [May 9, 2017, 3:13am UTC](https://qa.fmod.com/t/identify-sound-played-within-scatterer-sound/13165 "2017-05-09T03:13:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![uwejonas](https://avatars.discourse-cdn.com/v4/letter/u/5f9b8f/32.png) [@uwejonas](https://qa.fmod.com/u/uwejonas)
#### Post date: [May 9, 2017, 3:13am UTC](https://qa.fmod.com/t/identify-sound-played-within-scatterer-sound/13165/1 "2017-05-09T03:13:05Z")

</div>

I’ve managed to hook up an FMOD callback that fires when an event instance plays:

`
       FMOD.Studio.EventInstance evt = ...;
       evt.setCallback(OnFMODSoundplayed, FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED);
`

And within the callback I managed to get the name of the chosen sound within a scatterer sound:

`
   private static FMOD.RESULT OnFMODSoundPlayed(FMOD.Studio.EVENT_CALLBACK_TYPE type, System.IntPtr eventInstance, System.IntPtr parameters)
    {
            var sound = new FMOD.Sound(parameters);
            int nameLen = 1024;
            var nameBuilder = new System.Text.StringBuilder(nameLen);
            sound.getName(nameBuilder, nameLen);
            Debug.LogFormat("Playing sound {0}", nameBuilder);
    }
`

That is all fine and well, but it’s a lot of overhead and allocates tons of garbage each time a sound is playing, so not really practical in Unity.

I don’t _really_ need the name of the sound, any identifier to tell them apart would be enough. For example I’d be perfectly happy if I could query the _index_ of the sound within the list of sounds of a scatterer sound.

My idea was to go up from the sound playing to its parent scatterer sound and then down again into the list of children sounds, iterating over the list until I find a match. I have tried combinations of getSubSoundParent, getNumSubSounds, getSubSound, getSoundGroup, getNumSounds, and getSound, but to no avail. Both getNumSubSounds and getNumSounds always return 1.

So my questions are:

1. Is there a way to query the index of a sound playing within a scatterer sound?
2. Are scatterer sounds related to parent/sub sounds or sound groups at all?
3. Is the _parameters_ IntPtr in the callback guaranteed to be unique and non-changing for the entire runtime of a process, i.e. is the same sound within a scatterer sound always going to result in the exact same IntPtr value in the callback? That way I could cache sound names by IntPtr.

---

<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 9, 2017, 11:11pm UTC](https://qa.fmod.com/t/identify-sound-played-within-scatterer-sound/13165/2 "2017-05-09T23:11:05Z")

</div>

If it just a unique identifier for the one event, then the parameters IntPtr is unique for each sound added to the Scatterer. The scatterer creates an FMOD.Sound for each sound that it can then play when needed.

This uniqueness cannot be guaranteed globally though, as sounds get freed an created it may get replaced with another.

We are planning on reducing the overall overhead and garbage allocations of the Unity Integration in the near future.
