One of the older items on my to-do list was to give my sound designer a way to change the game’s audio without having to recompile the game in Visual Studio and start it up. Based on some of the improvements I made recently, I was finally able to knock that item off my to-do list.

Below, you can see a short annotated video walkthrough where I demonstrate the technique and show how it integrates with XACT.


There are a few key pieces necessary for this to work.

First, I need a way to get updated audio into the game. It turns out this is pretty simple – if you change the settings in your XACT project, you can get it to build output files into a folder of your choice. At that point, all you need to do is change your game’s XACT code to be able to load from that location.

Second, I need a way to pull information out of the XACT datafiles that I can use to attach cues to events. Since the XACT API provided by the XNA Framework is basically useless for this purpose, I ended up solving this problem by loading up the raw datafiles and pulling the names of my cues out of the datafiles. Yes, it’s disgusting. But it works! Luckily, the cue names are right at the end of the data files, and they’re null-terminated, so it’s not difficult to read them. It’s beyond my understanding why the framework developers opted not to provide the information.

Third, I needed a way to broadcast events from objects in my game world. The solution I ended up building for this was essentially an improved version of the event framework that I previously used for handling input events, like button presses. The framework allows me to ’subscribe’ to various types of events, either for a specific object, or for all objects that can broadcast that event. The ability to subscribe to all objects inexpensively gives me a straightforward way to say things like ‘whenever any creature gets hit by a rocket, play an explosion sound’, which is important.

Fourth, I needed a way to expose event information in an understandable manner, so that it would be easy to figure out what events are occurring in-game and how to attach sounds to them. I solved this by creating a simple ‘event overlay’ that shows a list of the most recently fired events, and highlights objects when they broadcast events. This allows you to simply play the game with the overlay open and look for things that are missing sound effects – once you find something, just look at the log to find out the name of the event.


If you’re interested, you can check out the source code and automated tests for the event system here, on Google Code. In the future I will be releasing the rest of my audio framework as open-source for people to use. Please don’t hesitate to leave a comment if you have any questions; I’d be glad to help explain more about how this technique works.