Playing and Stopping Multiple Instances using the same Singleton

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.

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



The simplest way of storing multiple event instances would be to replace m_eventInstance with some kind of collection. A List<EventInstance> would be a basic way to do this - inside FMODSoundManager.Play() you can use List<EventInstance>.Add() to add the new instance to the list, and then remove it from the list with List<EventInstance>.Remove() 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 keyword to a static FMODSoundManager method where you act on it.

Hope this helps!

1 Like

Hey, Louis,

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!

1 Like