# Example, C# Event Player with geometry Occlusion

**URL:** <https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338>\
**Category:** Unity\
**Created:** [March 14, 2014, 11:15pm UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338 "2014-03-14T23:15:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![atomtwist](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@atomtwist](https://qa.fmod.com/u/atomtwist)\
**Post date:** [March 14, 2014, 11:15pm UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338/1 "2014-03-14T23:15:43Z")

</div>

Version 1.0 - DOWNLOAD THE UNITYPACKAGE at the bottom

![](http://s30.postimg.org/3srloh51t/Screen_Shot_2014_03_14_at_11_07_04_PM.png)

Features:

1. Drag & Drop FMODAsset into Inspector
2. Automatically creates a List of all parameters & shows their names and min/max values in Inspector
3. Start On Awake checkbox
4. [fake] Geometry Occlusion

Setup:

1. Drag FmodEventPlayer.cs onto GameObject that should emit the sound.
2. Drag Event from Folder FMODAssets into the Asset field in the Inspector

Events:

Use the following commands to access the event instance:

```auto
soundEvent.start()
soundEvent.stop()
soundEvent.release()
etc...
```

Parameters:

Upon pressing Play in Unity, you’ll find all the event’s parameters within an array in the inspector,  
from where they can be accesed using the following syntax:

```auto
soundEventParams[0].setValue(newValue);
soundEventParams[1].setValue(newValue);
soundEventParams[3].getValue();
etc...
```

Note: The Inspector shows the parameters names & even their min/max values.

Occlusion:

!!! For Occlusion to work - your event needs to have a parameter that is called “Occlusion” with min/max values between [0-1].

1. Tick the Use Occlusion Box
2. Drag the GameObject that holds your FMOD\_Listener Component into the Fmod Listener field in the inspector

> [@](#):
>
> How the fake Occlusion works:
> 
> - It casts a lineCast from the soundSource to the Listener
> - if the lineCast hits something, the Occlusion parameter gets tweened & vice versa

TO DO:  
 → Add LayerMask Support for Occlusion Linecast

Note: FmodEventPlayer currently uses iTween, which I included in the unitypackage.

---

<div class="post-metadata">

**Author:** ![Guest1](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Guest1](https://qa.fmod.com/u/Guest1)\
**Post date:** [July 31, 2014, 11:53pm UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338/2 "2014-07-31T23:53:58Z")

</div>

> [@](#):
>
> Version 1.0 - DOWNLOAD THE UNITYPACKAGE at the bottom
> 
> ![](http://s30.postimg.org/3srloh51t/Screen_Shot_2014_03_14_at_11_07_04_PM.png)
> 
> Features:
> 
> 1. Drag & Drop FMODAsset into Inspector
> 2. Automatically creates a List of all parameters & shows their names and min/max values in Inspector
> 3. Start On Awake checkbox
> 4. [fake] Geometry Occlusion
> 
> Setup:
> 
> 1. Drag FmodEventPlayer.cs onto GameObject that should emit the sound.
> 2. Drag Event from Folder FMODAssets into the Asset field in the Inspector
> 
> Events:
> 
> Use the following commands to access the event instance:
> 
> ```auto
> soundEvent.start()
> soundEvent.stop()
> soundEvent.release()
> etc...
> ```
> 
> Parameters:
> 
> Upon pressing Play in Unity, you’ll find all the event’s parameters within an array in the inspector,  
> from where they can be accesed using the following syntax:
> 
> ```auto
> soundEventParams[0].setValue(newValue);
> soundEventParams[1].setValue(newValue);
> soundEventParams[3].getValue();
> etc...
> ```
> 
> Note: The Inspector shows the parameters names & even their min/max values.
> 
> Occlusion:
> 
> !!! For Occlusion to work - your event needs to have a parameter that is called “Occlusion” with min/max values between [0-1].
> 
> 1. Tick the Use Occlusion Box
> 2. Drag the GameObject that holds your FMOD\_Listener Component into the Fmod Listener field in the inspector
> 
> > [@](#):
> >
> > How the fake Occlusion works:
> > 
> > - It casts a lineCast from the soundSource to the Listener
> > - if the lineCast hits something, the Occlusion parameter gets tweened & vice versa
> 
> TO DO:  
> → Add LayerMask Support for Occlusion Linecast
> 
> Note: FmodEventPlayer currently uses iTween, which I included in the unitypackage.

The unity package is available here: [http://52.88.2.202/forum/download/file.php?id=189](http://52.88.2.202/forum/download/file.php?id=189)

---

<div class="post-metadata">

**Author:** ![Trumkey](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@Trumkey](https://qa.fmod.com/u/Trumkey)\
**Post date:** [April 16, 2014, 8:42am UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338/3 "2014-04-16T08:42:54Z")

</div>

You could make this a tad more user friendly by storing the parameters in a dictionary instead of a standard array. I had a go an this is what I came up with, it works too:

```auto
private FMOD.Studio.ParameterInstance p = null;
private FMOD.Studio.PARAMETER_DESCRIPTION description = new PARAMETER_DESCRIPTION();
public Dictionary<string, FMOD.Studio.ParameterInstance> parameters = new Dictionary<string, FMOD.Studio.ParameterInstance>();

void CacheEventParameters()
    {
        int parameterCount;
        ERRCHECK(evt.getParameterCount(out parameterCount));

        for (int i = 0; i < parameterCount; i++)
        {
            ERRCHECK(evt.getParameterByIndex(i, out p));
            ERRCHECK(p.getDescription(out description));
            parameters.Add(description.name, p);
        }
    }
```

So now you can reference parameters by their actual name instead of remembering their position in an array.

```auto
parameters["ParameterName"].SetValue(value);
```

I personally turned it into a function so all I need to do is call SetParameterValue(string, float).

---

<div class="post-metadata">

**Author:** ![atomtwist](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@atomtwist](https://qa.fmod.com/u/atomtwist)\
**Post date:** [April 17, 2014, 11:20am UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338/4 "2014-04-17T11:20:13Z")

</div>

cool stuff man - that’s really helpful - i never used dictionaries before - so i didn’t know how to do this.

very much appreciated !!! 🙂

---

<div class="post-metadata">

**Author:** ![bradowado](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@bradowado](https://qa.fmod.com/u/bradowado)\
**Post date:** [April 15, 2014, 6:24pm UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338/5 "2014-04-15T18:24:17Z")

</div>

Cool stuff, excited to try it out. Would love to see FMOD develop true occlusion and reflections like GSOUND [http://gamma.cs.unc.edu/GSOUND/](http://gamma.cs.unc.edu/GSOUND/) as well as true HRTF!

---

<div class="post-metadata">

**Author:** ![jsayre](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jsayre](https://qa.fmod.com/u/jsayre)\
**Post date:** [March 16, 2014, 5:50am UTC](https://qa.fmod.com/t/example-c-event-player-with-geometry-occlusion/11338/6 "2014-03-16T05:50:57Z")

</div>

Very much appreciated, thank you.
