Nerd For Tech
Published in

Nerd For Tech

An Introduction To Wwise Part 2: SFX

If you haven’t checked out the previous article, do so HERE as we have already covered some of the basic functionality of Wwise and will be skipping right ahead into Sound Effects. SFX are a key part to immersion in any form of visual media. In film, everything is linear, but when it comes to video games, we don’t know how the user is going to play the game. In our space shooter game, there is a lot of laser fire. The player will get pretty sick of the same sounds repeating themselves over and over again. But with middleware like Wwise, we can easily apply variations to all our sounds.

So let’s start with our Laser. First create a SFX Work Unit within our Actor-Mixer Hierarchy. Within this Work Unit, let’s create a Random Container. Now if we select this, we can import our sounds. We’re still prototyping and just getting the implementation sorted, so for now, let’s just use our singular placeholder Laser SFX.

The key purpose of a Random Container, is that we can populate it with multiple sound clips but simply call it to be played off one Event. Keeping our code within Unity short, leaving Wwise to internally process the rest. If we look near the top right of the image, we can see a section called Play Type, this allows us to run through our Container of clips randomly, or in sequence. We want to select Random and Standard, this functions as an ongoing random function, whereas Shuffle acts as a more traditional music playlist function in that each clip is removed from the pool after it is played. If we have a large amount of clips we can also adjust the amount of plays before hearing the same clip again.

Looking at the bottom of the image we can also see that we can set a Weight on each clip in the container, further allowing us to manipulate the randomness.

Since we only have one placeholder sound effect, let’s still create some variation by randomizing the pitch. This can be done by clicking the small circle on the left under our Voice Volume.

This allows us to add variation to our pitch with a minimum and maximum offset. Something so simple can immediately make our SFX feel much more immersive and well designed for a repeated sound.

We can simply repeat this process for our Explosion Sound and our Powerup Sound. Now we can create an Event for each that calls Play on our respective Random Containers.

Let’s jump back over to Unity and look at how we call Wwise Events from code.

If you haven’t already, make sure you either remove or inactivate the Audio Source and/or Audio Clip components on your Game Objects.

Our original Laser Sound got called from our Player script. We no longer need to write lines of code getting components and null checking. Instead we can create a private AK.Wwise.Event variable and Serialize it so we can assign our Event in the inspector.

Now in our FireLaser method we can Post the Event to Wwise.

By default, the positioning of our Containers in Wwise are set to Direct Assignment and thus do not follow any form of spatialization. Since we are in a 2D game, and our Listener is attached to the Camera, we can simply post the Event on this.gameObject. If we had a 3D game and wanted to have the laser sounds firing in various directions around the player, we would perhaps want to post the event to the laser object so the Audio Listener can read the appropriate spatialization properties.

Lastly, we just need to assign our Event in the Inspector. You will need to Regenerate your Soundbanks in Wwise and possibly refresh the project in the Wwise Picker window in Unity.

For our Explosion, we called it in two different ways. One on the Enemy within the EnemyDeath method and the other on our Explosion prefab in our Start method.

Much like the laser, these can both be assigned to AK.Wwise.Event variables in their respective scripts. Then in the respective methods we Post the Event on this.gameObject. A lot simpler than using Unity’s audio engine, and already with variation on our SFX.

Again, we can do the same on our Powerup script, Posting the Event in our OnTriggerEnter2D method. Even though our Powerup instantly Destroys itself on collision, our Wwise event is still called and played out as long as we have our Post funtion before our Destroy function. This is because our Wwise Event isn’t a component of the game object, instead once it’s called, Wwise does all the work independently. Thus we don’t have to worry about PlayClipAtPoint and finding the Listener Position to accurately place the SFX.

As I personally progress with the project, hopefully I will find some time and inspiration to create some of my own Music and Sound Effects, and we can look at some deeper forms of immersion within Wwise. I’ll be sure to post a part 3 when this happens! For now, I’m open to discussions or questions about further Audio Integration questions, either in the comment section here or over on my LinkedIn.

--

--

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