StudioEventEmitter.SetParameter() only works in Update()

Hello, I’ve used this method a lot in a previous project, but now it doesn’t seem to be working. Actually it does work if I use StudioEventEmitter.SetParameter(…) in my Update() function, but it doesn’t work if I use it in any one-time calls.

For instance, I want to modulate an impact sound in OnCollisionEnter() like this:

using UnityEngine;
using FMODUnity;

public class Drum : MonoBehaviour
{
    public float minImpact = .05f;
    public float impactVelocityThreshold = 20f;
    public StudioEventEmitter drumSound;

    private void OnCollisionEnter(Collision collision)
    {
        float hitForce = Mathf.Clamp01(collision.relativeVelocity.sqrMagnitude / impactVelocityThreshold);
        //Debug.Log("Hit Drum. Force = " + hitForce);
        if (hitForce > minImpact)
        {
            drumSound.SetParameter("HitForce", hitForce);
            drumSound.Play();
        }
    }

The code doesn’t return any errors but it doesn’t effect the sound either, it doesn’t seem like the parameter is being set. (I’ve double checked the spelling and the parameter’s automation curves.) Any idea what I should check for or if I should use a different method? Thanks so much for your time :slight_smile:

I think calling play is resetting to the initial StudioEventEmitter parameter value.
This might be a bug, or at least confusing behaviour, so I’ll raise with the Dev team- especially if you have found that it didn’t used to behave in this way.
Try swapping around the SetParameter and Play calls and let me know if it starts working properly, i.e

if (hitForce > minImpact)
{
    drumSound.Play();
    drumSound.SetParameter("HitForce", hitForce);
}

Oh nice! Yeah that works. Thanks for getting back to me so quickly!