StudioEventEmitter SetParameter not updating reliably


I’m new to FMOD. Quick and simple question - should I be able to do:

soundEmitter.SetParameter(switchParameterId, switchIsUp ? 0 : 1); // soundEmitter is a StudioEventEmitter

As I flip a switch in my game and have it work? Because it only works some of the time… it seems like the parameter is not always getting updated. It IS updating sometimes. If I put the SetParameter() line into Update(), it works every time. But then it’s constantly updating that parameter for every light switch in the game which is obviously undesirable.

FMOD Studio 2.02.05 and Unity 2021.2.7f1

Okay, it seems I misunderstood how this works. I read somewhere in the Steam Audio documentation that I had to have an FMOD Studio Event Emitter on the object to use a Steam Audio Source on it, but that seems to be untrue and I can do it like this with just an EventInstance.

switchState.setParameterByID(switchParameterId, switchIsUp ? 0 : 1); // switchState is an FMOD.Studio.EventInstance

But now my problem is that the sounds cut each other off. Here’s my event:

I was using the drawer sound just for testing so that it was super obvious when the parameter changed. When that longer drawer sound is playing and I flip the switch again, it gets cut off for the other sound to play. How can I avoid that?

Yikes, nevermind. Steam Audio Source does not seem to work with the EventInstance, or I am confusing myself further and broke it. :man_facepalming:

Now I’ve tried going back to something I was doing before. A StudioEventEmitter and a SteamAudioSource on the same object, two separate EventReferences (one for “on” event, one for “off” event), and just doing

private void EmitSound(EventReference eventRef)
        if (soundEmitter == null) return;

        soundEmitter.EventReference = eventRef;

when the switch is flipped. EmitSound() is called with onSound or offSound as the switch is flipped. Somehow that is only playing the on sound and not the off sound… the StudioEventEmitter is clearly updating the EventReference in the inspector, but is not playing the correct event.

The more I am working with these things the more confused I’m getting!

The only way I can manage to do what I’m wanting to do here and have it work 100% of the time is to create TWO StudioEventEmitters for the object and set each one’s EventReference in Start(). Then it plays the correct sounds and Steam Audio works (though there is still a lot for me to understand with how that all works as well).

Is that the typical way to do this? I feel like I should be able to do this with just the one StudioEventEmitter?

I think the last solution here is probably the simplest way to go about it. Otherwise, calling RuntimeManager.PlayOneShotAttached will handle the event starting and releasing for you nicely without cutting out existing event instances.

A big part of my problems is that I’m wanting Steam Audio to work with this. RuntimeManager.PlayOneShotAttached does not work with Steam Audio, it seems.

I see, if Steam Audio depends on a StudioEventEmitter to work correctly then I think having multiple event emitters is the way to go. Studio Event Emitters aren’t designed to have their events changed at runtime, with the RuntimeManager and API being preferred for such use cases.