# Changing parameters from a different script

**URL:** <https://qa.fmod.com/t/changing-parameters-from-a-different-script/15095>\
**Category:** Unity\
**Created:** [October 2, 2019, 10:19pm UTC](https://qa.fmod.com/t/changing-parameters-from-a-different-script/15095 "2019-10-02T22:19:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan1](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dan1](https://qa.fmod.com/u/dan1)\
**Post date:** [October 2, 2019, 10:19pm UTC](https://qa.fmod.com/t/changing-parameters-from-a-different-script/15095/1 "2019-10-02T22:19:58Z")

</div>

Greetings,  
I’m trying to write a code to change the value of a parameter, based on an in-game event.

I already have a Studio Event Emitter script on my FPSController (Unity’s default controller) and I’m trying to create a script on my enemy to trigger different music when it detects the player:

```
[FMODUnity.EventRef]
private string eventPath = "event:/Music/Music";
private FMOD.Studio.EventInstance studioInstance;

void Update()
{
    studioInstance = FMODUnity.RuntimeManager.CreateInstance(eventPath);

    if(playerDetected)
    {
        SetParameter(studioInstance, "Enemy", 1.0f);
    }
}

// Set an FMOD parameter 
void SetParameter(FMOD.Studio.EventInstance e, string name, float value)
{
    FMOD.Studio.ParameterInstance parameter;

    e.getParameter(name, out parameter);
    parameter.setValue(value);
}

```

The code above doesn’t change the parameter on the FPSController.  
I’m using FMOD 1.1, will appreciate any help,  
Thanks!

---

<div class="post-metadata">

**Author:** ![alexzzen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexzzen/32/6825_2.png) [@alexzzen](https://qa.fmod.com/u/alexzzen)\
**Post date:** [October 3, 2019, 3:52am UTC](https://qa.fmod.com/t/changing-parameters-from-a-different-script/15095/2 "2019-10-03T03:52:41Z")

</div>

You can’t get the Studio Event Emitter from the FPSController by creating a new Event Instance in another script. In simple terms, it’s like creating a new copy of the instance (that is not playing) with its own parameter instance. You should try to get a reference to the Studio Event Emitter already playing. Try something like this:

```
[SerializeField]
private FMODUnity.StudioEventEmitter emitter;

void Update()
{
    if (playerDetected)
    {
        SetParameter(emitter.EventInstance, "Enemy", 1.0f);
    }
}

void SetParameter(FMOD.Studio.EventInstance e, string name, float value)
{
    FMOD.Studio.ParameterInstance parameter;
    e.getParameter(name, out parameter);
    parameter.setValue(value);
}

```

Drag the GameObject with the FPSController/Studio Event Emitter to the empty Studio Event Emitter field in your Enemy’s inspector tab. By doing this, you get a reference to that specific Event Emitter. If you notice, we pass the Event Instance of the emitter to the `SetParameter` method : )

---

<div class="post-metadata">

**Author:** ![dan1](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dan1](https://qa.fmod.com/u/dan1)\
**Post date:** [October 3, 2019, 1:21pm UTC](https://qa.fmod.com/t/changing-parameters-from-a-different-script/15095/3 "2019-10-03T13:21:42Z")

</div>

Thank you so much! You have no idea how much I appreciate your help - works like a charm!
