I have a dilemma. I created an XAudio2 object in my second layout (a level) and made it Global. I have a ton of events set up for music and sound effect control throughout that level. I then went to my first layout (the main menu) and started adding sound effect events there as well. However they didn't play on the Main Menu, presumably because the XAudio2 object hadn't been loaded yet, since it was a part of the second layout - they only played on the Main Menu if I started a new game to get to the Level layout, then from that level returned to the main menu (with the XAudio2 object now loaded).
To get around this issue I created an event where an XAudio2 object would be created at the start of the Main Menu layout. Problem solved! The Main Menu now has sound effects right from the start! But... when I now start a new game there are TWO XAudio2 objects playing music and sound effects in the Level layout, leading to distortions and possibly even reduced performance.
Is there a way to destroy XAudio2 objects at runtime? Because I can't find the option anywhere. I imagine if I can destroy the XAudio2 object from the Main Menu just before the Level layout is loaded, the duplicate sound effects and music issues will be resolved.
The only other solution I can think of is to delete the global XAudio2 object from the Level layout (which would delete all of my sound effect and music events ) and start again, creating the base XAudio2 object on the Main Menu this time around. Obviously, I'd reeeeaaaaally like to not do that.
Thanks for reading. I hope someone can think of something