# Multiple sounds that can be activated, code doesn't work?

**URL:** <https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811>\
**Category:** Unity\
**Created:** [January 31, 2023, 4:54pm UTC](https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811 "2023-01-31T16:54:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Melodee](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/melodee/32/4629_2.png) [@Melodee](https://qa.fmod.com/u/Melodee)\
**Post date:** [January 31, 2023, 4:54pm UTC](https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811/1 "2023-01-31T16:54:32Z")

</div>

I tried this code so multiple sounds can be activated in the same scene but in different locations:

> ```auto
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine;
> 
> public class AudioCollider : MonoBehaviour
> {
> public GameObject audioObject;
>    
> // Start is called before the first frame update
> void Start()
> {
> audioObject = GameObject.FindGameObjectWithTag("Audio");
> }
> 
> void OnTriggerEnter(Collider other)
> {
> if (other.CompareTag ("Player"))
> {
> audioObject.SetActive(true);
> this.gameObject.SetActive(true);
> 
> }
> }
> }
> 
> ```

This is my setup for the code:

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

It doesn’t work, why?

---

<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 1, 2023, 2:32am UTC](https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811/2 "2023-02-01T02:32:20Z")

</div>

Hi,

The first issue is you can’t find `inactive` game objects. As the `Audio` objects are all set to inactive at the start they will never get assigned. An alternative would be calling `Play()` on the `Event Emitter` instead. All event emitter functions can be found under [FMOD Unity | Scripting API Reference](https://fmod.com/docs/2.02/unity/api-studioeventemitter.html).  
Your new code would look like this:

```auto
public class AudioCollider : MonoBehaviour
{
    public FMODUnity.StudioEventEmitter audioObject;
   
    // Start is called before the first frame update
    void Start()
    {
        audioObject = GameObject.FindGameObjectWithTag("Audio");
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag ("Player"))
        {
            audioObject.Play();
            this.gameObject.SetActive(true);
        }
    }
}

```

The added benefit is you have access to all the functions attached to the `Event Emitter`.  
Now you will want to set all your `Audio` objects to `Active` in the scene and make sure their `Play Event` option is set to none:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/1/1f993f95d165a9ecc10f317e8792c5375c8cf4ed.png)  
You can leave `Stop Event` to destroy to make sure memory is cleaned up properly.  
Are there any other errors being logged in the console window?  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/af39dbc733e303c1b06108838751802ffb190bdf.png)  
The console window is very useful too for debugging.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Melodee](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/melodee/32/4629_2.png) [@Melodee](https://qa.fmod.com/u/Melodee)\
**Post date:** [February 1, 2023, 1:24pm UTC](https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811/3 "2023-02-01T13:24:29Z")

</div>

thankyou ! that helps a lot!!  
it does give an error, i’ll try to find a way to fix it.

eitherway if anyone feels interested to find a solution: what the error is saying is that the Event Emitter is not a GameObject and it can not be assigned like such.

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

here’s my solution:

```auto
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine;
> 
> public class AudioCollider : MonoBehaviour
> {
> public GameObject audioObject;
> public FMODUnity.StudioEventEmitter playingaudio;
> 
> // Start is called before the first frame update
> void Start()
> {
> audioObject = GameObject.FindGameObjectWithTag("Audio");
> }
> 
> void OnTriggerEnter(Collider other)
> {
> if (other.CompareTag("Player"))
> {
> playingaudio.Play();
> }
> }
> 
> void OnTriggerExit(Collider other)
> {
> if (other.CompareTag("Player"))
> {
> playingaudio.Stop();
> }
> }
> }

```

---

<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 1, 2023, 9:51pm UTC](https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811/4 "2023-02-01T21:51:16Z")

</div>

Apologies, to solve the error

You could do something like

```auto
public class AudioCollider : MonoBehaviour
{
    public FMODUnity.StudioEventEmitter audioPlaying;
    public GameObject audioObject;
   
    // Start is called before the first frame update
    void Start()
    {
        audioObject = GameObject.FindGameObjectWithTag("Audio");
        audioPlaying = audioObject.GetComponent<FMODUnity.StudioEmitter>();
    }

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Melodee](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/melodee/32/4629_2.png) [@Melodee](https://qa.fmod.com/u/Melodee)\
**Post date:** [February 2, 2023, 1:12pm UTC](https://qa.fmod.com/t/multiple-sounds-that-can-be-activated-code-doesnt-work/19811/5 "2023-02-02T13:12:21Z")

</div>

It’s ok! The other thing already helped a lot but this helps even more.
