# How to reach a bool parameter inside FMOD event?

**URL:** <https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [February 12, 2024, 10:07pm UTC](https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233 "2024-02-12T22:07:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheBossaWorks](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/thebossaworks/32/6220_2.png) [@TheBossaWorks](https://qa.fmod.com/u/TheBossaWorks)\
**Post date:** [February 12, 2024, 10:07pm UTC](https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233/1 "2024-02-12T22:07:53Z")

</div>

Hello,

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

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/4/4b14851cde2fce09d749f2b7a7f0201530bc063f.png)

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.

```auto
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!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [February 13, 2024, 3:06am UTC](https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233/2 "2024-02-13T03:06:30Z")

</div>

Hi,

First, we will need to have access to the [FMOD::Studio::EventInstance](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html), so rather than using `PlayOneShot` we will rather need to use the `EventReference` to create an instance using [FMODUnity.RuntimeManager.CreateInstance](https://fmod.com/docs/2.02/unity/api-runtimemanager.html#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](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_start) and as the docs recommend we will call [EventInstance::release](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_release) immediately after to make sure the instance is cleaned up when it finishes playing.

```auto
[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](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_setparameterbynamewithlabel) on our instance to set the parameter. I would suggest also checking the instance is still valid by calling [EventInstance::isValid](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_isvalid).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![TheBossaWorks](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/thebossaworks/32/6220_2.png) [@TheBossaWorks](https://qa.fmod.com/u/TheBossaWorks)\
**Post date:** [February 15, 2024, 8:39pm UTC](https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233/3 "2024-02-15T20:39:44Z")

</div>

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).

```auto
 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);

 }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/8/8594c97c6edb38335ae987c12f4ee89938afb1dc.png)

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [February 16, 2024, 1:55am UTC](https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233/4 "2024-02-16T01:55:00Z")

</div>

Hi,

Can you try this change:

```auto
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](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_setparameterbynamewithlabel:~:text=label%2C%0A%20%20bool%20ignoreseekspeed%20%3D%20false%0A) is “PickedUpObject”, and the [label](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_setparameterbynamewithlabel:~:text=8%20string) 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](https://fmod.com/docs/2.02/api/core-api-common.html#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](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/b1811c89c59d36aabf5ab83b743ed22770bf1aee.png)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/5/545b3ed2971b3c89d152d2f37627202b6e7652b6.png)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![TheBossaWorks](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/thebossaworks/32/6220_2.png) [@TheBossaWorks](https://qa.fmod.com/u/TheBossaWorks)\
**Post date:** [February 16, 2024, 3:19am UTC](https://qa.fmod.com/t/how-to-reach-a-bool-parameter-inside-fmod-event/21233/5 "2024-02-16T03:19:31Z")

</div>

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!

```auto

    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();
    }

```
