# How do I retrieve a parameter from a StudioEventEmitter in Unity ?

**URL:** <https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770>\
**Category:** Unity\
**Created:** [October 24, 2016, 2:07pm UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770 "2016-10-24T14:07:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgstudio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/pgstudio/32/750_2.png) [@pgstudio](https://qa.fmod.com/u/pgstudio)\
**Post date:** [October 24, 2016, 2:07pm UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770/1 "2016-10-24T14:07:35Z")

</div>

Hi Guys,

I’m doing this code to set a parameter in unity:

FMODUnity.StudioEventEmitter musicEvent;  
var target = GameObject.Find(“MyGameObject”);  
musicEvent = target.GetComponent\<FMODUnity.StudioEventEmitter\>();  
musicEvent.SetParameter (“War”, 1.0f);

And it’s working well…

What I want is to retrieve the value of this parameter later on.

For example:

if (MyParameter ==1) {  
MyCode();  
} else {  
MyOtherCode();  
}

Something like:  
FMOD.Studio.ParameterInstance myParameter;  
myParameter = musicEvent.GetParameter (“War”);

What’s the best way to do this ??  
Thanks

---

<div class="post-metadata">

**Author:** ![berli](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@berli](https://qa.fmod.com/u/berli)\
**Post date:** [November 2, 2016, 5:30am UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770/2 "2016-11-02T05:30:12Z")

</div>

float x = 1f;

musicEvent.SetParameter (“War”, x);

x is the value that you change, so use x.

---

<div class="post-metadata">

**Author:** ![pgstudio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/pgstudio/32/750_2.png) [@pgstudio](https://qa.fmod.com/u/pgstudio)\
**Post date:** [November 2, 2016, 10:30am UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770/3 "2016-11-02T10:30:56Z")

</div>

> [@](#):
>
> float x = 1f;
> 
> musicEvent.SetParameter (“War”, x);
> 
> x is the value that you change, so use x.

What I wanted was to avoid using a var just for that. but thanks anyway

---

<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:** [November 2, 2016, 9:47pm UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770/4 "2016-11-02T21:47:40Z")

</div>

You are basically on the money.

Create an event.  
Create a parameter instance.  
You will need to refer to the parameter by name/string.  
Then you can call myParameter.setValue or getValue to change the parameter on the fly. Unfortunately the get function of ParameterInstance doesn’t return a value but outputs it to a given variable.

musicEvent = target.GetComponent\<FMODUnity.StudioEventEmitter\>();  
FMOD.Studio.ParameterInstance myParameter;  
myParameter = musicEvent.GetParameter (“War”);

myParameter.getValue(out float);  
myParameter.setValue(float);

---

<div class="post-metadata">

**Author:** ![pgstudio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/pgstudio/32/750_2.png) [@pgstudio](https://qa.fmod.com/u/pgstudio)\
**Post date:** [November 2, 2016, 11:12pm UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770/5 "2016-11-02T23:12:57Z")

</div>

> [@](#):
>
> You are basically on the money.
> 
> Create an event.  
> Create a parameter instance.  
> You will need to refer to the parameter by name/string.  
> Then you can call myParameter.setValue or getValue to change the parameter on the fly. Unfortunately the get function of ParameterInstance doesn’t return a value but outputs it to a given variable.
> 
> musicEvent = target.GetComponent\<FMODUnity.StudioEventEmitter\>();  
> FMOD.Studio.ParameterInstance myParameter;  
> myParameter = musicEvent.GetParameter (“War”);
> 
> myParameter.getValue(out float);  
> myParameter.setValue(float);

Hey Cameron, thanks for your reply.  
The problem is that GetParameter is not a method of the StudioEventEmitter Object. It’s a method of the EventInstance object. ☹

---

<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:** [November 2, 2016, 11:58pm UTC](https://qa.fmod.com/t/how-do-i-retrieve-a-parameter-from-a-studioeventemitter-in-unity/12770/6 "2016-11-02T23:58:27Z")

</div>

Sorry, the StudioEventEmitter does have Params which returns an array of FMODUnity.ParamRef you can use the same as a ParameterInstance.  
For example:

```
for (int i = 0; i < emitter.Params.Length; i++)
{
       if (emitter.Params[i].Name == "ParamterName")
       {
           param = emitter.Params[i];
       }
}
Debug.Log(param.Value);
param.Value += 0.1f;
```
