Parameter not changing in FMOD - scripting help

Hi, I’m trying to get up and running in FMOD 2.0.02. I have an event “fightSongs” that plays a different song based off a parameter “songSelect” but I can’t seem to get unity sending the float value to FMOD properly. Any suggestions? I’m in Unity 2018.3.3f1

public class SongSwitcherScript : MonoBehaviour
{
FMOD.Studio.EventInstance fightSongs;
public float songNumber;

public void SetSong()
{
    fightSongs.setParameterByName("songSelect", songNumber);
}

void Update()
{
    SetSong();
    Debug.Log("Song is:"+ songNumber);
}

}

Are there any errors? Have you checked the studio profiler and looked at the parameter value?

As far as I can remember, and without looking at the API, set parameter returns a FMOD.RESULT. I’d check that value first.

Then look into silly things like the spelling of the parameter.

Maybe log how many parameters are on the event. Set the parameter by index and see if that works.

I’m not 100% sure and I can’t test right now, but I think you are trying to change a parameter on an instance you haven’t created or haven’t assigned yet. Just declaring the instance is not enough.

Solution 1: Find the script where you are creating and playing the actual fightSongs instance.

private SomeScript script;
[SerializeField]
private float songNumber;

private void Start() 
{
    script = GameObject.Find("GameObjectName").GetComponent<SomeScript>();
}

public void SetSong()
{
    script.fightSongs.setParameterByName("songSelect", songNumber);
}

Solution 2: Since you are using FMOD 2+ you could use a Global Parameter to change the songs.
For that you just need one line of code, without referencing any event. Make sure to change the parameter from local to global in FMOD Studio for this behaviour.

private void SetSong() 
{
     FMODUnity.RuntimeManager.StudioSystem.setParameterByName("songSelect", songnNumber);
}

Thanks. This second solution worked great for what I’m doing. So is there no way to directly call a local param? You have to direct it toward the script that’s playing the fmod event?

You can only call functions on a valid Event Instance, one that has been created through the FMOD System either yourself or from a StudioEventEmitter script.

See the scripting examples for examples on creating sounds and adjusting parameters.