Parameter final value is not changing

Hello.
I try to change the value of the parameter during runtime, but the final value does not change for some reason and because of this the parameter does not affect the sound in any way.

I also noticed that if I set the “Persistent” parameter to “On”, everything works. Should I leave this parameter enabled or am I doing something wrong?

using FMODUnity;
using UnityEngine;

public class Test : MonoBehaviour
{
    public StudioEventEmitter emitter;
    public float value = 1.0f;

    [ContextMenu("SetParameterAndPlay")]
    private void SetParameterAndPlay()
    {
        emitter.EventInstance.setParameterByName("RestSecondsToNight", value);
        emitter.EventInstance.getParameterByName("RestSecondsToNight", out float a, out float b);
        emitter.Play();

        UnityEngine.Debug.Log($"value: {a}"); // print right value
        UnityEngine.Debug.Log($"final value: {b}"); // print 10 (default value)
    }
}

Thanks.

Hi,

Thank you for sharing the detailed setup, and sorry for the late response.

finalvalue represents the fully processed value of the parameter after applying adjustments due to automation, modulation, seek speed, and parameter velocity to value. This is calculated asynchronously when the studio system updates.

To ensure the parameter value is fully applied without enabling the Persistent setting, could you please try calling Studio::System::flushCommands right after setParameterByName? This forces the system to process all pending changes right away.

Also, make sure to set the parameter after calling emitter.Play(), so that you’re applying the value to the currently active event instance.

For example:​

using FMODUnity;
using UnityEngine;

public class Test : MonoBehaviour
{
    public StudioEventEmitter emitter;
    public float value = 1.0f;

    [ContextMenu("SetParameterAndPlay")]
    private void SetParameterAndPlay()
    {
        emitter.Play();
        emitter.EventInstance.setParameterByName("RestSecondsToNight", value);
        RuntimeManager.StudioSystem.flushCommands();
        emitter.EventInstance.getParameterByName("RestSecondsToNight", out float a, out float b);

        UnityEngine.Debug.Log($"value: {a}"); // print right value
        UnityEngine.Debug.Log($"final value: {b}"); // print 10 (default value)
    }
}

Hope this helps, let me know if the issue persists.

Indeed, changing the execution order helped. You need to first execute emitter.Play and only then change the variables. Thanks

1 Like