# Stop Playing OneShot?

**URL:** <https://qa.fmod.com/t/stop-playing-oneshot/19854>\
**Category:** FMOD Engine\
**Created:** [February 9, 2023, 2:39am UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854 "2023-02-09T02:39:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![libio1991](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@libio1991](https://qa.fmod.com/u/libio1991)\
**Post date:** [February 9, 2023, 2:39am UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/1 "2023-02-09T02:39:04Z")

</div>

Good Evening,

I am playing a sound like this:

```auto
public EventReference sound;

public void PlaySound()
{
       RuntimeManager.PlayOneShot(sound);
}

```

This works, but I need to stop it early sometimes.  
What is the simplest way to stop playing this sound before it finishes?

Thanks!

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [February 9, 2023, 5:04am UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/2 "2023-02-09T05:04:17Z")

</div>

Hi,

To stop an event instance before its natural end, you need a reference to it, which `PlayOneShot()` obviously doesn’t give you. However, `PlayOneShot()` is simply executing the following code,

```auto
var instance = RuntimeManager.CreateInstance(/* your EventReference here */);
instance.set3DAttributes(RuntimeUtils.To3DAttributes(position));
instance.start();
instance.release();

```

so I’d recommend copying that code and using it instead of calling `PlayOneShot()`, and storing the instance yourself so you can call `instance.stop()` with the appropriate [stop mode](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_stop_mode) when needed.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![libio1991](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@libio1991](https://qa.fmod.com/u/libio1991)\
**Post date:** [February 9, 2023, 5:00pm UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/3 "2023-02-09T17:00:29Z")

</div>

Thanks for the reply again Leah, this definitely helps!

Though this does bring up two questions:

1. For the line:  
`"instance.set3DAttributes(RuntimeUtils.To3DAttributes(position));"`  
This is if I want 3D sound, i.e, sound that plays relevant to the listener, right? If I want the sound to be uniform and the same volume, (2D?) can I just leave this out?

2. Is this different than instance.stop()? Do I need to release every instance that I store in addition to stopping it?

Thanks again for taking the time!

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [February 9, 2023, 11:04pm UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/4 "2023-02-09T23:04:12Z")

</div>

No problem!

1. This line is (put simply) for when you want to play a 3D sound, as it provides FMOD with the position and velocity of your sound so that it can be spatialized. If you want the sound to be unaffected by spatialization, and it doesn’t have a Spatializer effect on it, then you can ignore that line. If the event does have a Spatializer effect, then you’ll want to keep the line and set the position to match your listener.

2. It is different from `instance.stop()` - [`instance.release()`](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_release) marks the event for release, meaning that it will be destroyed by FMOD when it has stopped playing. Best practice is to call release after starting any event instances when you no longer need to change their playback state, unless you want to play the same instance multiple times, or explicitly stop an instance and start it again later.

---

<div class="post-metadata">

**Author:** ![libio1991](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@libio1991](https://qa.fmod.com/u/libio1991)\
**Post date:** [February 10, 2023, 12:39am UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/5 "2023-02-10T00:39:07Z")

</div>

Makes perfect sense! Thanks for the assistance!

---

<div class="post-metadata">

**Author:** ![Gmanmondo](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@Gmanmondo](https://qa.fmod.com/u/Gmanmondo)\
**Post date:** [April 3, 2024, 9:19am UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/6 "2024-04-03T09:19:11Z")

</div>

What if I want to do this but with PlayOneShotAttached()? What would be different? I can’t seem to get the sound to stay on the player.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [April 4, 2024, 3:38am UTC](https://qa.fmod.com/t/stop-playing-oneshot/19854/7 "2024-04-04T03:38:10Z")

</div>

For an equivalent to `PlayOneShotAttached()`, instead of setting the event instance’s 3D attributes, you would call `RuntimeManager.AttachInstanceToGameObject()` to get the event instance to follow the player’s transform.
