Muting audio when interacting with game object in unity

Hey! I’m struggling to figure out how to get this setup to work: I have a radio object which I can interact with in Unity, and I want this interact to toggle between muting and unmuting a continuously playing FMOD event. How would I implement this?

I’m quite new to FMOD Unity by the way

Hi,

Thank you for sharing the information.

If your radio object is using a StudioEventEmitter, a simple way is to toggle the volume of its event instance when the object is interacted with.

For example:

using UnityEngine;
using FMODUnity;

public class RadioMuteToggle : MonoBehaviour
{
    public StudioEventEmitter radioEmitter;
    private bool muted;

    private void Update()
    {
        // press P to test mute/unmute
        if (Input.GetKeyDown(KeyCode.P))
        {
            Interact();
        }
    }

    public void Interact()
    {
        muted = !muted;
        radioEmitter.EventInstance.setVolume(muted ? 0f : 1f);
    }
}

Add this script to your radio object, assign the same StudioEventEmitter to radioEmitter, then press P to test it. In your own project, you can call Interact() from your interaction system instead.

This mutes/unmutes the radio while the event keeps playing in the background.

If you want the radio to pause instead, you can use Studio::EventInstance::setPaused instead of Studio::EventInstance::setVolume in Interact().

For example:

radioEmitter.EventInstance.setPaused(muted);

Hope this helps!