# Playing different SFX depending on a parameter

**URL:** <https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446>\
**Category:** Unity\
**Created:** [February 27, 2022, 7:40pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446 "2022-02-27T19:40:07Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [February 27, 2022, 7:40pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/1 "2022-02-27T19:40:07Z")

</div>

We use a labeled parameter to play different sounds for different magic types.  
Both the Unity and the FMOD we use have been updated today and nothing works still.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/a9e2403d93f54a08b1802090783dd03d28e92335.png)  
despite setting the parameter to “Light” it plays the default sound still. We tried using discrete as well, doesn’t work either.  
Maybe something with the fact it’s labeled? Though, according to the API, that’s how it should be used …right?  
Helplease.

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [March 1, 2022, 1:20am UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/2 "2022-03-01T01:20:15Z")

</div>

From my testing, `setParameterByNameWithLabel()` works as intended. There are a few variables that could be in play here. Could you please check the following:

- There are no seek speeds or velocity settings on the `magicType` parameter
- The `magicType` parameter is not set to read only or is not a global parameter
- Are there any warnings or errors being logged in the Unity console
- Are you able to do the same actions but using a more direct approach with game code (manually instantiate and set the parameter of the event in a script) rather than manipulating the EventEmitter?

---

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [March 1, 2022, 5:50pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/3 "2022-03-01T17:50:55Z")

</div>

Hey there, thanks for doing your best to help.  
The first three the answer is no.  
As for the fourth- it does work if we it set in the editor window, but we need it to work from within the code.

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [March 2, 2022, 12:27am UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/4 "2022-03-02T00:27:53Z")

</div>

Are you able to do the code more like this in a new script and see if that works:

```auto
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class setEventLabel : MonoBehaviour
{
    public FMODUnity.EventReference eventReference; // Select your event from the game object
    FMOD.Studio.EventInstance eventInstance;

    // Start is called before the first frame update
    void Start()
    {
        eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventReference);
        eventInstance.start();
        eventInstance.setParameterByNameWithLabel("magicType", "Light");
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

```

---

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [March 2, 2022, 6:10pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/5 "2022-03-02T18:10:36Z")

</div>

The programmer says that thats exactly what he did but it didn’t work.

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [March 3, 2022, 12:29am UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/6 "2022-03-03T00:29:35Z")

</div>

Are you able to put this event into a new project and send it over? Right click \> Copy onto the event in question, open a new blank FMOD Studio project and paste. It should bring across all relevant assets and bus routing. Feel free to delete the assets if you don’t wish to share it. Then could you send that new project to me in a DM and I’ll take a closer look?

---

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [March 7, 2022, 6:11pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/7 "2022-03-07T18:11:24Z")

</div>

Hey there, just wanted to make sure you got the mail (sent it a few days ago)

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [March 7, 2022, 7:33pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/8 "2022-03-07T19:33:21Z")

</div>

Yes, it has arrived thanks. It was assigned to my queue yesterday and I’m taking a look into it now.

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [March 7, 2022, 10:33pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/9 "2022-03-07T22:33:50Z")

</div>

I’ve taken a look and everything in the project appears fine. It looks like what is happening is you are setting the parameter value on the event instance of the event emitter, but what you need to do is set the parameter on the emitter directly _before_ playing it (the emitter will cache the parameters until Play is called).

```auto
soundObj.GetComponent<FMODUnity.StudioEventEmitter>().SetParameter("MagicType", 0.75f);
soundObj.GetComponent<FMODUnity.StudioEventEmitter>().EventInstance.setParameterByNameWithLabel("MagicType", "Light");

```

Currently, the `EventEmitter.SetParameter()` function does not support labels so you can either implement it yourself or just use floats.

---

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [March 8, 2022, 2:28pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/10 "2022-03-08T14:28:44Z")

</div>

ok I’ll talk to the programmer about it.  
Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [April 18, 2022, 7:38pm UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/11 "2022-04-18T19:38:23Z")

</div>

Hello! Writing to you back through here because…

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

I’m trying to run an event that is set up like any other in Unity, it runs in the banks and other events run well.  
What could be the problem?  
Big thanks in advance 🙂  
I’m attaching a video with the problem recorded

(Attachment 2022-04-18 22-34-36.mkv is missing)

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [April 19, 2022, 2:49am UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/12 "2022-04-19T02:49:41Z")

</div>

I’m unable to see the video you’ve tried to attach, but does the console log any warnings or errors when this event is played?

---

<div class="post-metadata">

**Author:** ![Rabbival507](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@Rabbival507](https://qa.fmod.com/u/Rabbival507)\
**Post date:** [April 19, 2022, 7:36am UTC](https://qa.fmod.com/t/playing-different-sfx-depending-on-a-parameter/18446/13 "2022-04-19T07:36:02Z")

</div>

No, none at all…
