# Can't get C# script to change an FMOD Parameter?

**URL:** <https://qa.fmod.com/t/cant-get-c-script-to-change-an-fmod-parameter/19034>\
**Category:** Unity\
**Tags:** csharp\
**Created:** [July 20, 2022, 5:26pm UTC](https://qa.fmod.com/t/cant-get-c-script-to-change-an-fmod-parameter/19034 "2022-07-20T17:26:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amazzamati](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@amazzamati](https://qa.fmod.com/u/amazzamati)\
**Post date:** [July 20, 2022, 5:26pm UTC](https://qa.fmod.com/t/cant-get-c-script-to-change-an-fmod-parameter/19034/1 "2022-07-20T17:26:34Z")

</div>

Hi,

I’ve been trying to have a slider in Unity control a parameter in FMOD.  
This is the first script that I tried:

```auto
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FMODParameters : MonoBehaviour
{

    FMODUnity.StudioEventEmitter changeVolume;

    FMOD.Studio.EventInstance bass;

    public string bassVolumeParameter;

    public Slider slider;

    

    void Start()
    {
        changeVolume = GetComponent<FMODUnity.StudioEventEmitter>();

        bass = FMODUnity.RuntimeManager.CreateInstance("event:/Beat/2D/2D Bass");

        slider = GetComponent<Slider>();

      
    }

   
   

    void SetBassVolume(float _value)
    {
        bass.setParameterByName(bassVolumeParameter, slider.value / 250);
        
    }
}

```

But then, the OnValueChanged of the slider in unity wouldn’t show the dynamic parameters so I couldn’t really use it.

So then I have tried this one:

```auto
[FMODUnity.EventRef]
public string NAME EVENT = “event:/EVENT”;
public FMOD.Studio.EventInstance AUDIO EVENT;
public FMOD.Studio.ParameterInstance PARAMETER EVENT;

void Start () {
AUDIO EVENT = FMODUnity.RuntimeManager.CreateInstance(NAME EVENT);
AUDIO EVENT.getParameter(“NAME PARAMETER FMOD”, out PARAMETER EVENT);
AUDIO EVENT.start();
}

void OnTriggerEnter(Collider other)
{
PARAMETER EVENT.setValue(VALUE IN FLOAT);
}

```

which I’ve found on this forum but it gives me the error CS0234: The type or namespace name ‘ParameterInstance’ does not exist in the namespace ‘FMOD.Studio’ (are you missing an assembly reference?)  
and CS1061: ‘EventInstance’ does not contain a definition for ‘getParameter’ and no accessible extension method ‘getParameter’ accepting a first argument of type ‘EventInstance’ could be found (are you missing a using directory or assembly reference?)

I’m a bit of a noob with coding, so anyone has encountered any of these issues before?  
Alternatively, what’s the simplest way to get a C# script to change an FMOD parameter?

Thanks in advance for the help!

---

<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:** [July 21, 2022, 4:47am UTC](https://qa.fmod.com/t/cant-get-c-script-to-change-an-fmod-parameter/19034/2 "2022-07-21T04:47:56Z")

</div>

Hi,

Your first attempt was really close! Just a few things were missing.

If You are trying to change the volume on `FMODUnity.StudioEventEmitter changeVolume` then what you want to call is:

```auto

changeVolume.EventInstance.setParameterByName("YourParam", slider.value);

```

This will change the volume on the `parameter` on the `changeVolume` variable.

If you are wanting the change the volume on `FMOD.Studio.EventInstance bass` there a few things to do first, you will want to do this in the `Start()` function:

> **Initializing bass EventInstance**
>
> ```auto
> 
> // This part is perfect
> bass = FMODUnity.RuntimeManager.CreateInstance("event:/Beat/2D/2D Bass");
> 
> // We should check if the instance was created properly
> // It is always a good idea to Debug check often 
> If (bass.isValid() != true)
> {
> Debug.Log("Failed to create bass instance");
> }
> 	
> // FMOD.RESULT is a very useful tool for debugging most of FMOD's function calls, use it where ever you can. 
> FMOD.RESULT result; 
> 	
> // We will now need to start the instance through code, as we have created the instance in code
> result = bass.start();
> 	
> If (result != FMOD.RESULT.OK)
> {
> // Now we check if the function ran correctly or if there was an error, we will know when it happened and what the result is.
> Debug.Log("Failed to start instance with the result of " + result); 
> }
> 		
> 
> // We call release so that when the sound is stopped the memory is freed
> result = bass.release(); 
> 
> ```

Some things to fix in the `SetBassVolume()` function. It doesn’t require any parameters as we are getting the value from the `slider` which is a member variable. So we could just have the function set like this:

```auto
	Public void SetBassVolume()
	{
		bass.setParameterByName(bassVolumeParamter, slider.value); 
		
	// Alternatively if you want to change the value of `changeVolume` you would call 
		changeVolume.EventInstance.setParameterByName(bassVolumeParamter, slider.value); 
	// But that will depend on which instance you decide to use. 
	// Now when ever this function is called it will set either instances volume parameter to the same value as the `slider`
	}

```

This function could be attached to a button or called in `Update()` to check if it is working.

Really good examples of how to use the FMOD API can be found under [Unity Integration](https://fmod.com/docs/2.02/unity/welcome.html) → [Scripting Examples | Basic](https://fmod.com/docs/2.02/unity/examples-basic.html). If you are ever confused about what the API is doing then [Welcome to FMOD API](https://fmod.com/docs/2.02/api/welcome.html) is the best place to start looking!

Could you possibly link the forum post where you found that scripting example as well?

Hope this helps!
