Wwise to Unity Integration Cheat Sheet for Beginners.

This list will continue to get updated as I discover more tips and tricks for how to integrate audio into Unity! Anyone is welcome to use these codes to learn Wwise themselves.

You may have gotten through the 101, 201 and 251 courses through Audiokinetic’s website, but you still might not know how to actually INTEGRATE these Events, States and RTPC’s you set up into Unity. I don’t blame you – this information is for some reason, incredibly difficult to find online. But you need to know, in order to get your Wwise integrated into Unity. So let’s get started!

 

Fundamental Integration through C#

 

In Unity, the most common way of using Wwise is by calling upon the “AkSoundEngine.____” in your C# Scripts.

This does mean that it will immensely help you if you understand the basics of C# and how scripts work. I’d highly recommend you take your time to learn what void, Start, Update, if, how functions work and reading scripts. While you won’t be doing coding most of the time, you will be searching for appropriate places to insert these codes. In many of your games, you’ll have to ask your programmer for instructions on which scripts you need to squeeze these in. But, if they’re organized programmers and if you’re keeping track of where everything is, you won’t need to waste their time asking for obvious places to code them.
What you want Wwise to do is now up to you. That ______ can be filled out by you to determine what you want Wwise to do. The most basic ones that you’ll use is PostEvent, SetRTPCValue, SetState.

AkSoundEngine.PostEvent( ” EventName” , gameObject);

For sending out a message to Wwise to trigger an Event, you use PostEvents. This is good for one-time actions.
Useful for: Collision sounds, button click sounds, weapon fire sound, you can even use it to trigger the music to play at the Start of your game.

AkSoundEngine.SetState (“State Group name”, “State Name”);

For sending out a message to Wwise to set a State.  This is great for letting Wwise know what state you’d like to be in.
Useful for: Changing your adaptive music with States. Telling Wwise what Level you are, whether your game is Paused or not, whether you’re underwater or not. 

AkSoundEngine.SetRTPC( “RTPC Name in Wwise”, variableNameInUnity);

For setting RTPC (Real Time Parameter Control) of any value that you’d like to be reflected by a value in Unity, you can use this.
Useful for: Any numerical value, like Health, How many kills you’ve gotten, your high score, your car’s speed, setting the volume of your SFX or Music channel in the options menu.

In the image below, you can see that there are several lines of AkSoundEngine scripts I put into my “State_InGame” script in Unity.

Screenshot1. AkSoundEngine. is calling Wwise.

2. SetState( ) is telling Wwise to prepare to do an action: set State. But now you have to tell Wwise which state group and to what state you’d like to target.

3. (“Group”, “State”); In each quotation marks, you can put the name of your Group and the name of your State.

Now, your script is ready. What should we do with it? Let’s take that script, and attach it to anything you want. I like to give my scripts that set states into a GameStateSetter game object, so that I can always look for it quickly. Since the void Start () function will trigger at the very first frame when this gameobject loads into the scene, Unity will tell Wwise to set your state and play the corresponding music.
Screenshot2.png

That’s really about as hard as it gets. Congratulations! You now understand the fundamentals of actual integration.

General Tips & Tricks

0. Connect to your Unity and use Wwise in real time. Man, did this blow my mind when I first understood what “Connect” and “Remote” really meant. You can use this to mix audio in your game in real time as you’re playtesting the game. Furthermore, it allows you to monitor how many ‘voices’ are active in your game and how much processing power your audio is using. It’s so useful.

Screenshot3.png

1. Names of Events, State Groups, RTPC’s are all in ” “. Names of your in-game variables are not. For example, below, you can see that my “MusicVolume” is in quotations. This script sets the “MusicVolume” to musicVolume. This is how you do Volume settings,  by the way.

Screen Shot 2018-07-27 at 1.40.36 AM.png

2. Calling Game events. You have to put “gameObject” as the target for posting your event. This means that whatever Event you just posted, it’ll associate itself with the gameObject that this script is attached to. Without this later part, your PostEvent script will not function.

Screen Shot 2018-07-28 at 4.27.29 PM.png

3. The order of your actions matter. In this case, Sprinkler sound should play first, then Setting Valve, then finally Set State to On. If I put Set State to On first and then Sprinkler, Sprinkler plays at 0.Screen Shot 2018-07-28 at 4.24.58 PM.png

4. Ways to integrate Ambient sounds into your game. Notice that Wwise Picker tab that appeared in your Unity project. Most of the times, you won’t have to deal with it. However, there are sometimes like setting Ambiences or Reverb zones when you do want to drag objects from this bar directly onto your objects. If it’s not an ambient sound that will be emitted from an object, you don’t have to place the Event into an object to get it to play. This way, sounds won’t just burst out at the beginning of your game. (Since you have to load it by Start, Awake or one of the Collision options).

This was a confusion that I had because when I was first learning to use PostEvent, I watched a woman integrate sounds onto her cubes as her ball was rolling into them to pick them up. (If you’ve watched this video). She has it set so that these sounds will play when these objects are being Destroyed. Unless you want your sounds to play when your objects are being destroyed, you do NOT want to integrate your sounds this way. Attaching it on a script that says “AkSoundEngine.PostEvent(“Pickup”, gameObject); and then having these functions activate is better practice.

5. When working with buttons, if you want a previously playing music to stop, you must add a Stop action to the Event, and make sure that its Scope is set to Global and not GameObject.

Screen Shot 2018-08-16 at 5.19.57 PM.png

6. Attach an AkGameObj script onto a prefab or a gameObject in order to store information like Events, RTPC, and position!

7. Adding a brief pause function so that it only detects the first moment of an action- For example: You have a bird that accelerates when you click and hold right click. The moment you press, you want a blast of air sound to go off, but don’t want it to be played every frame while you’re holding right click. 

Brief Pause function.png

This is great because you can call upon the void stop(); later on to pause your current script, which will resume after that amount of specified time.

8. Adding “Typing” sound effects to only Keyboard inputs. Call any KeyDown, and exclude Mouse 1 and Mouse 2. If you want a “Submit” sound, add it to the script that actually disables/destroys this script. Adding it here won’t be fast enough.

Screen Shot 2018-10-05 at 11.19.22 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s