# Playing and Stopping Multiple Instances using the same Singleton

**URL:** <https://qa.fmod.com/t/playing-and-stopping-multiple-instances-using-the-same-singleton/19735>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [January 13, 2023, 3:19pm UTC](https://qa.fmod.com/t/playing-and-stopping-multiple-instances-using-the-same-singleton/19735 "2023-01-13T15:19:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Settingscon](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Settingscon](https://qa.fmod.com/u/Settingscon)\
**Post date:** [January 13, 2023, 3:19pm UTC](https://qa.fmod.com/t/playing-and-stopping-multiple-instances-using-the-same-singleton/19735/1 "2023-01-13T15:19:40Z")

</div>

Hey everyone,

I’m building a manager\* to take care of all the FMOD functionalities I want to use. The problem I’m having is that whenever I create 2 event instances, the 1st m\_eventInstance gets overwritten and can never be stopped. As my code is right now, that’s the expected behaviour, I just don’t know what I should do to fix this. I apologize if it’s something obvious, I did try my best to research, and I’m also fairly new to programming and couldn’t come up with any great solutions on my own.

 ![FMODSoundManager](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/2/28452d16672db24106a6d90743d317f892ed153c.jpeg)

Ideally, I still wanted to have all functionalities in one class. Maybe making it a singleton was a mistake?

Cheers!

---

<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:** [January 15, 2023, 11:45pm UTC](https://qa.fmod.com/t/playing-and-stopping-multiple-instances-using-the-same-singleton/19735/2 "2023-01-15T23:45:56Z")

</div>

Hi,

The simplest way of storing multiple event instances would be to replace `m_eventInstance` with some kind of collection. A [`List<EventInstance>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=net-7.0) would be a basic way to do this - inside `FMODSoundManager.Play()` you can use [`List<EventInstance>.Add()`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add?view=net-7.0) to add the new instance to the list, and then remove it from the list with [`List<EventInstance>.Remove()`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.remove?view=net-7.0) in `FMODSoundManager.Stop()`. However, this also comes with other issues, primarily how you’ll manage tracking and accessing individual event instances for specific purposes (e.g. setting parameters).

Depending on the needs of your project, you may be able to accomplish this with your singleton class, but it might be worth rethinking your approach to systematizing event management. Having a static class to handle common calls isn’t a bad idea, but as we typically think of audio as being tied to individual sources, it may be more intuitive to relate each event to its source instead of a singleton manager. For example, you could store each event instance in a script attached to its “source” game object, and then pass a given instance by reference using the [`ref`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref) keyword to a static `FMODSoundManager` method where you act on it.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Settingscon](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Settingscon](https://qa.fmod.com/u/Settingscon)\
**Post date:** [January 16, 2023, 12:37am UTC](https://qa.fmod.com/t/playing-and-stopping-multiple-instances-using-the-same-singleton/19735/3 "2023-01-16T00:37:37Z")

</div>

Hey, Leah,

I see! I understand what you are saying, and in fact I’ll definitely try to approach this in a different way, similar to your suggestion.

I truly appreciate the thorough reply, I’m still learning and I feel like this was valuable information (haven’t found this anywhere else).

Thank you!
