# Position, Index and Callback OnEnter attenuation of a listener

**URL:** https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660
**Category:** Unity
**Created:** [September 16, 2023, 12:21pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660 "2023-09-16T12:21:13Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [September 16, 2023, 12:21pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/1 "2023-09-16T12:21:13Z")

</div>

Sorry for a lame question.  
Is it possible to get Position, Index and Callback onEnter of a listener in attenuation without Unity collisions?  
I’m guessing FMOD is constantly receiving this info, maybe there is a way to get it.  
By using Unity collisions we would duplicate process or I’m mistaken?

---

<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: [September 18, 2023, 2:59am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/2 "2023-09-18T02:59:24Z")

</div>

Hi,

Could you elaborate on the functionality you are looking for? If you look at `StudioListener.cs` you are able to use `ListnerCount()` to retrieve the current index of the listener. There is also the `listeners` list that you can use to check all the other listeners. You could track the position of the listeners yourself using the list and avoid having to use collisions. Let me know if the helps.

---

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [September 19, 2023, 7:14pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/3 "2023-09-19T19:14:21Z")

</div>

Sorry, didn’t give you any context. I’m thinking about stereo audio system for split screen car game.  
I want every event has panning parameter (every event that I need to be panned). This parameter depend on proximity of event to listeners. Which one is closer those channel gets more signal from event.  
So thank you for  
RuntimeManager.StudioSystem.getListenerAttributes(0, out FMOD.ATTRIBUTES\_3D attributes); this is what I need to get distance to sound source (event).  
But I need also to know if a listener is inside attenuation radius. I can calculate it by finding distance to event, but I don’t like an idea every event has a script to calculate distance to two listeners all the time.  
So maybe there is a sort of event (delegate) which indicates that a listener is inside attenuation?

---

<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: [September 21, 2023, 6:05am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/4 "2023-09-21T06:05:35Z")

</div>

Hi,

Thank you for the explanation. A solution may be to use the `FMOD_STUDIO_EVENT_CALLBACK_VIRTUAL_TO_REAL` callback ([FMOD Engine | Studio API Reference - FMOD\_STUDIO\_EVENT\_CALLBACK\_TYPE](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_event_callback_type)). With the events stealing behavior set to virtualization ([FMOD Studio | Advanced Topics - Stealing](https://fmod.com/docs/2.02/studio/advanced-topics.html#stealing-and-virtualization:~:text=Virtualize%3A%20(Event%20Only)%20The%20quietest%20event%20instance%20is%20virtualized%2C%20meaning%20it%20continues%20to%20play%20but%20produces%20no%20output%20until%20an%20existing%20event%20instance%20stops%20or%20it%20is%20no%20longer%20the%20quietest%20event%20instance%20to%20the%20listener))  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/9/91b233c9c726a1c59d263beb5cdce1795b604aea.png)

The callback is triggered when an event becomes `real` and is heard by a listener. An example for setting up a callback can be found here: [Unity Integration | Scripting Examples - Timeline Callbacks](https://fmod.com/docs/2.02/unity/examples-timeline-callbacks.html)

Let me know if this is the behavior you are looking for.

---

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [September 23, 2023, 11:37am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/5 "2023-09-23T11:37:34Z")

</div>

Thank you. I didn’t have much time to experement this week.  
I set a `FMOD_STUDIO_EVENT_CALLBACK_VIRTUAL_TO_REAL` but it works only if the same event is present on scene and it becomes real or virtual. With only one event present this callback isn’t triggered, at least I can’t make it happen, I might certainly miss something.  
The only solution I can think of is to make one event for athmospheres so it would be only one real possible. Also first spawned event (possiblly) takes back voice once player leave another instances, means that it doesn’t leave current event virtual but passes virtual voice to first one.

---

<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: [September 26, 2023, 11:54pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/6 "2023-09-26T23:54:32Z")

</div>

Hi,

How many events are typically playing in the scene?

> [@doudar41](#):
>
> I can calculate it by finding distance to event, but I don’t like an idea every event has a script to calculate distance to two listeners all the time.

If there is a limited number of events, I feel this may be your best solution.

The virtualization solution should work if you have lots of events constantly moving in and out of audible range.

Apologies if I miss-understood, could I get another explanation or would it be possible to get the Unity and FMOD Studio project [uploaded](https://fmod.com/profile#uploads) to your [profile](https://fmod.com/profile) to test on my end? Keep in mind you will have to register a project with us to be able to upload.

---

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [September 27, 2023, 7:03pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/7 "2023-09-27T19:03:41Z")

</div>

You really helped me, thank you. And you understood right I don’t have a lot of objects on scene. 8 cars, 4-5 location based sounds, and some NPCs walking around. Cars have most complicated sound system, but in split screen it’s easy, all sounds will go to separate channel. So I’ll use distance calculation.

Still I’d love to share project I hope I’ll do it on weekend so we can discuss if my implementation of virtualization was right. If it’s possible. I have few questions about it. I need to make some basic project for that, because unity project I’m reseaching for isn’t ready and too big.

---

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [October 1, 2023, 12:15pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/8 "2023-10-01T12:15:36Z")

</div>

Ok, I put project here [GitHub - doudar41/SplitScreenFMODPan](https://github.com/doudar41/SplitScreenFMODPan.git) This is not a company project just test one so I’m not sure if I need to register it. If it’s better option I’ll do it.  
The result is like this [https://youtu.be/zaphUb9P-Uk](https://youtu.be/zaphUb9P-Uk)  
I couldn’t make singleton that would instantiate event for each game objects, so it’s a bit mess.  
But hopefully an idea is understandable.

---

<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: [October 4, 2023, 12:10am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/9 "2023-10-04T00:10:34Z")

</div>

Hi,

Thank you for the project. I can now see the issue with using the event callback. There is still an option but it is a bit more involved. There is the `VOL0 Vritual` init flag ([FMOD Studio | White Papers - VOL0 Virtual](https://fmod.com/docs/2.02/api/white-papers-virtual-voices.html#vol0-virtual)) that will virtualize any channel that has its audibility drop below a certain threshold. However, this is for channels rather than events which is part of the `core api` system. Also, we will have to get the channel from the event instance which when using referenced events is a bit more confusing.

This is definitely an option but calculating the distance from each object may be an easier way to go. Let me know your thoughts.

Again, thank you for the project.

---

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [October 4, 2023, 7:14am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/10 "2023-10-04T07:14:10Z")

</div>

Thank you for this. I think I need a bit more understanding of Core API to test this one. I want to finish different project I started before so I’ll let you this one to wait for some time. But if you can give a hint of how to get channel from event instance that would be great.  
I appreciate your help. Thank you again.

---

<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: [October 9, 2023, 5:17am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/11 "2023-10-09T05:17:54Z")

</div>

Hi,

Unfortunately, I was mistaken. This idea won’t work using referenced events as you won’t be able to access their channels. Would it be possible to change the `Athmos` event so that it does not use referenced events? If so, then the set up will also be a lot easier as well.

---

<div class="post-metadata">

### Author: ![doudar41](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/doudar41/32/5163_2.png) [@doudar41](https://qa.fmod.com/u/doudar41)
#### Post date: [October 9, 2023, 8:31am UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/12 "2023-10-09T08:31:30Z")

</div>

Yeah, I just didn’t think that it might be a problem, because I don’t know how to access event channel yet. I used it to make a setup “solo” event easier)) more organized, because athmopheres will be not that simple as they are now. But anything is possible till I started to implement it into the game)

---

<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: [October 11, 2023, 9:35pm UTC](https://qa.fmod.com/t/position-index-and-callback-onenter-attenuation-of-a-listener/20660/13 "2023-10-11T21:35:58Z")

</div>

Hi,

Thanks for the info. With the simpler setup, retrieving the channel is quite straightforward.

1. We get the channel group from the event instance: [FMOD Engine | Studio API Reference - getChannelGroup](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_getchannelgroup).
2. Work down the `channelgroups` till we find the `channel`.

- Check if the current group has any `channels`: [FMOD Engine | Core API Reference - getNumChannels](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getnumchannels).
- If this returns 0 then we will need to check if there are more `channelgroups`: [FMOD Engine | Core API Reference - getNumGroups](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getnumgroups), and continue the process and work down the groups: [FMOD Engine | Core API reference - getGroup](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getgroup).

1. Once the channel is found we will grab it: [FMOD Engine | Core API Reference - getChannel](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getchannel).
2. Now we will set the new callback: [FMOD Engine | Core API Reference - setCallback](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getgroup).
3. Using the flag `VritualVoice`: [FMOD Engine | Core API Reference - FMOD\_CHANNELCONTROL\_CALLBACK\_TYPE](https://fmod.com/docs/2.02/api/core-api-channelcontrol.html#fmod_channelcontrol_callback_type).

Hopefully, this will outline the process of retrieving the correct channel and assigning the correct callback.
