# Can unity Check if certain fmod event is playing?

**URL:** https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342
**Category:** Unity
**Created:** [December 25, 2019, 6:32pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342 "2019-12-25T18:32:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![tomerxcore](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tomerxcore](https://qa.fmod.com/u/tomerxcore)
#### Post date: [December 25, 2019, 6:32pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/1 "2019-12-25T18:32:01Z")

</div>

Hey , im trying to create a sound effect script for jet pack jump in a game i work on.  
I wondered if theres a way I could check if for example:

if Jetpack event is playing , return true

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/1X/1985b742ff85388b86d8780cfe27da36db0f7518.png)

is this possible ?

---

<div class="post-metadata">

### Author: ![alexzzen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexzzen/32/6825_2.png) [@alexzzen](https://qa.fmod.com/u/alexzzen)
#### Post date: [December 25, 2019, 11:59pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/2 "2019-12-25T23:59:34Z")

</div>

If you are managing instances you can call [EventInstance::getPlaybackState](https://www.fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventinstance.html#studio_eventinstance_getplaybackstate) to get the current playback state of an instance, something like this would work:

```
bool IsPlaying(FMOD.Studio.EventInstance instance) {
	FMOD.Studio.PLAYBACK_STATE state;   
	instance.getPlaybackState(out state);
	return state != FMOD.Studio.PLAYBACK_STATE.STOPPED;
}

```

If you are using the StudioEventEmitter components you can reference your desired emitter in code and call [StudioEventEmitter::IsPlaying](https://www.fmod.com/resources/documentation-unity?version=2.0&page=api-studioeventemitter.html#studioeventemitter_isplaying).

---

<div class="post-metadata">

### Author: ![tomerxcore](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tomerxcore](https://qa.fmod.com/u/tomerxcore)
#### Post date: [December 26, 2019, 2:17pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/3 "2019-12-26T14:17:58Z")

</div>

hi alex ! thanks for the replay  
can you show me an example of how it is done ?  
im pretty new to coding

how do I chose which event does the “isPlaying” is checking ?

---

<div class="post-metadata">

### Author: ![alexzzen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexzzen/32/6825_2.png) [@alexzzen](https://qa.fmod.com/u/alexzzen)
#### Post date: [December 27, 2019, 11:51am UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/4 "2019-12-27T11:51:38Z")

</div>

I suppose you are playing sounds using the StudioEventEmitter component:

![grafik](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/1X/9e0ca2b300e94c23c372f58dc2e7da8a5741bba2.png)

Create a new script and declare a StudioEventEmitter at the start of the class:

```
[SerializeField]
private FMODUnity.StudioEventEmitter emitter;

```

Save the script and attach it to any GameObject you want. Drag the GameObject containing the StudioEventEmitter component to the emitter field in the inspector:

![grafik](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/1X/9e752738227eb53dc8b1f58d8f7c236b6ad83f93.png)

Now you just can call the `isPlaying` method to check if that specific emitter is playing or not:

```
void Update()
{
    if (emitter.IsPlaying())
    {
        Debug.Log("Emitter is playing");
    }
    else if (!emitter.IsPlaying())
    {
        Debug.Log("Emitter is not playing");
    }
}

```

If you are still new to coding, I would suggest to take a look at [Unity’s learning resources](https://learn.unity.com/), they are great to learn how Unity works and to get basic scripting knowledge.

---

<div class="post-metadata">

### Author: ![tomerxcore](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tomerxcore](https://qa.fmod.com/u/tomerxcore)
#### Post date: [December 27, 2019, 4:12pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/5 "2019-12-27T16:12:45Z")

</div>

im actually planing on making a script with Update that checks if the sound is playing  
if he’s playing do nothing , else play the sound

that kinda solves me the whole jetpack thing  
how should i reference the specific Jetpack event doing so in the script  
with no emitter ?

---

<div class="post-metadata">

### Author: ![tomerxcore](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tomerxcore](https://qa.fmod.com/u/tomerxcore)
#### Post date: [December 27, 2019, 4:26pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/6 "2019-12-27T16:26:37Z")

</div>

ill ask this differently , where should i put the “isPlaying” method script so i could call it anywhere on every event instance ?

cause right now i put it on some AudioManager script i have ,  
and called it from a different script , and it doesnt seem to work

---

<div class="post-metadata">

### Author: ![alexzzen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexzzen/32/6825_2.png) [@alexzzen](https://qa.fmod.com/u/alexzzen)
#### Post date: [December 27, 2019, 5:31pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/7 "2019-12-27T17:31:23Z")

</div>

> how should i reference the specific Jetpack event doing so in the script  
> with no emitter ?

How are you actually playing your jetpack event? If by creating and playing an event instance in a script, then you can use the code snippet posted in my first answer in the same script.

> where should i put the “isPlaying” method script so i could call it anywhere on every event instance ?

There are different ways to go about this, you could make the method static so you can access it everywhere:

```
public class FmodExtensions
{    
    public static bool IsPlaying(FMOD.Studio.EventInstance instance)
    {
        FMOD.Studio.PLAYBACK_STATE state;
        instance.getPlaybackState(out state);
        return state != FMOD.Studio.PLAYBACK_STATE.STOPPED;
    }
}

```

Then just call `FmodExtensions.IsPlaying(yourInstance)` from where you want.

---

<div class="post-metadata">

### Author: ![tomerxcore](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tomerxcore](https://qa.fmod.com/u/tomerxcore)
#### Post date: [December 27, 2019, 7:19pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/8 "2019-12-27T19:19:21Z")

</div>

I finally managed to make it work ! your commends was super helpful .  
I put the IsPlaying() as a public static method in my main AudioPlayer script which controls several audio commands for the entire project ,  
then called it as you sayed

This is the how it works in the end :

```
	void Update ()
	{
		if (jetpack.UsingJet) 
		{
            if (AudioPlayer.IsPlaying(JetpackEvent))
            {
			
	        }  
	        else
	        {
	            JetpackEvent.start();
	        }
        }
        else 
        {
        	JetpackEvent.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
        }
	}
```

---

<div class="post-metadata">

### Author: ![memop](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@memop](https://qa.fmod.com/u/memop)
#### Post date: [November 29, 2022, 6:48pm UTC](https://qa.fmod.com/t/can-unity-check-if-certain-fmod-event-is-playing/15342/9 "2022-11-29T18:48:26Z")

</div>

yo guys also make your instance static if you want the same music to play in different scenes cuz it took me two hours to understand that
