Space Shooter: Using Switch Containers

In this article I want to go over how to set up a switch container. Theres several reasons to use them, but in this example I am going to use a switch container to handle the sound effects for each power up when collected. They should all have their own unique sound. I only want to use 1 event to handle this though. SO lets get into it!

In Wwise, I have set up a separate work unit to contain my power up sounds. Within the work unit I have a Switch Container and an audio file that holds the sound effect I want to play for each power up.

If you check out the Switch Container’s Property Editor you’ll notice a Contents Editor window. This is where you associate the SFX files with specific switches. Currently, we dont have any switches. SO we need to create some.

The Game Syncs tab is where you handle creating Switches and many other Game Syncs. I’ll get into some of these later on. For now, I’ve created a Switch group within a work unit called PowerUps.

I named the switches accordingly.

Now go back to your switch container’s property editor.

In the Switch section, click the arrows next to the Group. Select your newly created switch group.

Now your contents editor should be populated with information similar to this. Be sure to drag the file from the left to the switch it belongs to on the right.

Create a single event from the switch container. I called mine “PowerUpCollected”.

Add this event to a soundbank of your choice and generate them. After that head back into Unity.

Right now I have a script that handles the Power Up behavior. So I think I’ll develop the logic for specific sound effects to player from there.

To deal with switches you simply need an event and a switch. I’ve declared these at the top of the PowerUp script.

Since each power up uses the same script I can assign the switch in the inspector of each one.

For example: the ammo power up prefab:

The collected sound is the event. I simply dragged it into the field from the Wwise Picker. If you click on the empty switch field it will open a menu showing you all the switches associated with the switch group. All you have to do is assign the correct switch to each power up.

Then to actually make the correct sound play, you need to set the value of the switch before the event is called. For Example, the Shield Switch (case 2)

I simply set the value to the game object since the switch value is already assigned in the inspector. Then I post the event. Easy peezy!!

We just made a super modular power up sound effect system. This can be useful for all kinds of other situations. Footsteps detecting different surfaces for example.

Result here:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store