How to reach a bool parameter inside FMOD event?

Hello,

I’m having problems with reaching a property parameter inside a music event which is a boolean.

In scripting perspective how can I reach this parameter?

Here’s a manager I set up currently, you can skip to the last part of the script to see my problem.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMODUnity;
using UnityEditor.MPE;
using UnityEngine.Playables;

public class FMODEvents : MonoBehaviour
{

    [field: Header("Music")]
    [field: SerializeField] public EventReference sarahRoomMusic { get; private set; }
    [field: SerializeField] public EventReference hallwayMusic { get; private set; }


    [field: Header("Ambiance")]
    [field: SerializeField] public EventReference stairWellAmbiance { get; private set; }
    [field: SerializeField] public EventReference rainAmbiance { get; private set; }


    [field: Header("Item & Interaction")]
    [field: SerializeField] public EventReference uiInteractSFX { get; private set; }
    [field: SerializeField] public EventReference keyPickup { get; private set; }
    [field: SerializeField] public EventReference notePickup { get; private set; }


    [field: Header("Footstep Specific")]
    [field: SerializeField] public EventReference footStep { get; private set; }

    [field: Header("Clothes SFX")]
    [field: SerializeField] public EventReference clothesRustling { get; private set; }

    [field: Header("Mannequins")]
    [field: SerializeField] public EventReference headTurns { get; private set; }
    [field: SerializeField] public EventReference mannequinMovement { get; private set; }
    [field: SerializeField] public EventReference maskRattle { get; private set; }

    [field: Header("Flashlight")]
    [field: SerializeField] public EventReference flashlightClick { get; private set; }
    [field: SerializeField] public EventReference flashlightPickup { get; private set; }

    [field: Header("Walkie-Talkie")]
    [field: SerializeField] public EventReference walkiePickup { get; private set; }

    [field: Header("Damage Indicator")]
    [field: SerializeField] public EventReference takingDamage { get; private set; }

    EmitterGameEvent sarahRoomTrigger;

    public static FMODEvents instance { get; private set; }
    

    FMOD.Studio.Bus Music;
    FMOD.Studio.Bus SFX;
    FMOD.Studio.Bus Master;

    float MusicVolume = 0.5f;
    float SFXVolume = 0.5f;
    float MasterVolume = 1f;

    public float musicVolume = 1;


    private void Awake()
    {
        if(instance != null)
        {
            Debug.LogError(" Found more than one FMOD Events instance in the scene");
        }
        instance = this;

        //Music = FMODUnity.RuntimeManager.GetBus("bus:/Master/Music");
        //SFX = FMODUnity.RuntimeManager.GetBus("bus:/Master/SFX");
        //Master = FMODUnity.RuntimeManager.GetBus("bus:/Master");

    }

    private void Start()
    {
        //PlayMusic();
        
    }

    private void Update()
    {
        /*
        Music.setVolume(MusicVolume);
        SFX.setVolume(SFXVolume);
        Master.setVolume(MasterVolume);
        */
    }

    /*
    public void MasterVolumeLevel(float newMasterVolume)
    {
        MasterVolume = newMasterVolume;
    }

    public void MusicVolumeLevel(float newMusicVolume)
    {
        MusicVolume = newMusicVolume;
    }

    public void SFXVolumeLevel(float newSFXVolume)
    {
        SFXVolume = newSFXVolume;
    }
    */

    public void SetMusicVolume()
    {
        
    }

    public void PlayHallwayMusic()
    {
        AudioManager.instance.PlayOneShot(FMODEvents.instance.sarahRoomMusic, this.transform.position);
    }

    public void PlaySarahRoomMusic()
    {
        AudioManager.instance.PlayOneShot(FMODEvents.instance.hallwayMusic, this.transform.position);
    }

    public void PlayRainAmbiance()
    {
        AudioManager.instance.PlayOneShot(FMODEvents.instance.rainAmbiance, this.transform.position);
    }

    public void PlayStairWellAmbiance()
    {
        AudioManager.instance.PlayOneShot(FMODEvents.instance.stairWellAmbiance, this.transform.position);
    }

    public void PlayerNoteInteraction()
    {
        AudioManager.instance.PlayOneShot(FMODEvents.instance.notePickup, this.transform.position);
    }

    public void SarahRoommMusicChange()
    {
        FMOD.Studio.PARAMETER_ID id = //HOW TO REACH TO THE PARAMETER PROPERT?!?!

    }

}

Please help and thank you!

Hi,

First, we will need to have access to the FMOD::Studio::EventInstance, so rather than using PlayOneShot we will rather need to use the EventReference to create an instance using FMODUnity.RuntimeManager.CreateInstance.

Now that we are in control of the instance we are in charge of playing stopping and releasing it.

We will call EventInstance::start and as the docs recommend we will call EventInstance::release immediately after to make sure the instance is cleaned up when it finishes playing.

[field: SerializeField] public EventReference sarahRoomMusic { get; private set; }
private EventInstance sarahRoomMusicInst;

public void PlayHallwayMusic()
{
    sarahRoomMusicInst = FMODUnity.RuntimeManager.CreateInstance(sarahRoomMusic);
    sarahRoomMusicInst.start();
    sarahRoomMusicInst.release();
}

Finally, we will want to call EventInstance::setParameterBynameWithLabel on our instance to set the parameter. I would suggest also checking the instance is still valid by calling EventInstance::isValid.

Hope this helps!

Hi Connor,

Thx for reaching out! This does help me to understand how we create instances for FMOD Events however even with the documentation reaching the specified boolean is still confusing and complex. I’ll share with you how I’m trying to build but please assist me with reaching a particular parameter (in this case it’s a boolean).

 public void PlaySarahRoomMusic()
 {
     //AudioManager.instance.PlayOneShot(FMODEvents.instance.hallwayMusic, this.transform.position);

     sarahRoomMusicInst = FMODUnity.RuntimeManager.CreateInstance(sarahRoomMusic);
     sarahRoomMusicInst.start();
     sarahRoomMusicInst.release();
     sarahRoomMusicInst.setParameterByNameWithLabel(PickupObject, label, false);

 }

Hi,

Can you try this change:

public void PlaySarahRoomMusic()
 {
     //AudioManager.instance.PlayOneShot(FMODEvents.instance.hallwayMusic, this.transform.position);

     sarahRoomMusicInst = FMODUnity.RuntimeManager.CreateInstance(sarahRoomMusic);
     sarahRoomMusicInst.start();
     sarahRoomMusicInst.release();
     FMOD.RESTULT result = sarahRoomMusicInst.setParameterByNameWithLabel("PickupObject", "False");
     if (result != FMOD.OK)
         Debug.Log(result);
 }

In this instance, the name is “PickedUpObject”, and the label is the value we want to set the parameter to “True” we don’t have to pass in a value for ignoreseekspeed for now.

I have also added an FMOD.RESULT check which will help in debugging issues that may be occurring.

Could I also get a screenshot of the parameter in the Preset Browser:
image

Hope this helps!

Hey Connor!

Thank you so much for your help! This made it clear and we figured out how to work with this. The confusion from my side as a Unity Developer is that when I saw the True/False I immediately assumed it was a boolean created by the designer. Similar to the logic of int or float.

In case anyone has a similar confusion and finds themselves here I’m sharing how we created methods to control the sounds. Your feedback is also welcome!


    public void parameterChange(EventInstance eventInstance, string parameterName, string label)
    {
        eventInstance.setParameterByNameWithLabel(parameterName, label);
    }


    public void startFX(EventInstance eventInstance, EventReference eventReference)
    {
        eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventReference);
        eventInstance.start();
    }

    public void stopImmediateFX(EventInstance eventInstance, EventReference eventReference)
    {
        eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
        eventInstance.release();
    }

    public void stopFadeFX(EventInstance eventInstance, EventReference eventReference)
    {
        eventInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
        eventInstance.release();
    }
1 Like