Accessing Inbuilt Parameters via API

Hello,

I am trying to “expose” FMOD’s inbuilt parameters for educational reasons. I have recently built a very simple game level where distance, direction, elevation and event cone angle are displayed in game letting the student not only “hear” the changes in sound but also “see” the parameters change to have a better understanding of the parameters themselves.

To achieve this, I have calculated these parameters manually using the player and emitting object’s transform. However, I struggle to believe there is no way to get the FMOD inbuilt parameters from a Unity script and display them.

The API Docs say that " Studio::EventInstance::get3DAttributes" will return some vectors, which is not really what I need.

Has anyone attempted this before?

You can indeed get FMOD’s built-in parameters from a Unity script - the methods you’re looking for are Studio::EventInstance::getParameterByName and Studio::EventInstance::getParameterByID, both of which will return the value of a built-in parameter to the 3rd argument, finalvalue.

Hi @Leah_FMOD, thanks for the reply.

I have tried the two methods above, and whilst I can get “a” value from the FMOD Instance, this value is always stuck at the maximum value for a floating point (3.40282347E+38) which is weird because the FMOD event works, and as I approach the cube that holds the script, the attenuation curve is clearly having an effect on the sound. Any ideas what I might be doing wrong?

public class Test : MonoBehaviour
{
    private FMOD.Studio.EventInstance instance;

    float outvalue;

    void Update()
    {
        GetCubeTransform();

        if (Input.GetKeyDown("p"))
        {
            instance = FMODUnity.RuntimeManager.CreateInstance("event:/Distanza");
            instance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(cubeTransform));
            instance.start();
            instance.getParameterByName("Distance", out outvalue);
            Debug.Log(outvalue);
            instance.release();
        }
    }

    void GetCubeTransform(){
        GameObject cube = GameObject.Find("Cubo_Distanza");
        if (cube != null) {
            cubeTransform = cube.transform;
        }
    }
}

I simplified the code even more, using some a suggested implementation found here, and now I get 3.40282347E+38 when trying to access parameterValue, and 0 when trying to access finalParameterValue.

    float parameterValue;
    float finalParameterValue;
    public FMODUnity.EventReference eventRef;
    FMOD.Studio.EventInstance eventInst;

    void Start()
    {
        eventInst = FMODUnity.RuntimeManager.CreateInstance(eventRef);
    }

    void Update()
    {
        eventInst.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
        eventInst.getParameterByName("Distance", out parameterValue, out finalParameterValue);
        Debug.Log($"FPV {finalParameterValue}");
    }

The simplified code is missing calls to eventInst.start() and eventInst.release(). Add them, and getParameterByName should output what you’re looking for to finalParameterValue.

Built-in parameter values are automatically updated based on the 3D attributes of the associated event instance and the listeners in your scene - the value of a built-in parameter is never used and should be set to 0 by default (that it’s set to float max is a bug we’re working on). Likewise, attempting to set the value of a built-in parameter yourself will cause an error.

finalvalue is the value of a given parameter after it has been adjusted by automation, modulation, seek speed, etc. by FMOD. For built-in parameters, finalvalue has the data that you want.

Hope that helps!

Thank you @Leah_FMOD !

1 Like