Wwise Integration and C# Code

These are the steps to integrate a new Wwise project with a fresh build of the Unity Roll-a-Ball tutorial. These steps are also here for slightly older versions of Unity & Wwise

  1. Create a new Unity project OR import a tutorial file from the Unity Asset Store.
  2. Save Scene & Project.
  3. Quit Unity.
  4. Open Wwise Launcher. Go to the Unity tab and find your project.
  5. Click the blue Integrate Wwise into Unity button. Review the stats... This will be different depending on current version numbers at the time you do this. Just be sure that versions of Wwise are identical for both the middleware editing application and the Unity integration package.
  6. Click Integrate; sit tight…
  7. Click Open in Wwise to open the relevant Wwise project. Get to work! Once you have completed your SFX and music cues, you can bundle everything in a sound bank and get it ready for Unity in the next step.
  8. Choose Layouts > SoundBank and click SoundBanks Tab. Create a new soundbank called MAIN as a Child of the Default Work Unit.
  9. Drag MAIN to the Default Work Unit in the SoundBank Manager.
  10. Tick the boxes for Platform and Language as appropriate.
  11. Click Generate at the top of the SoundBank Manager.
  12. Switch to the Events Tab. Drag all of your audio events to MAIN (in the SoundBank Manager window) and click Generate once again. A dialog box will appear when this process is complete. Check to see that number of media items is correct in the Log.
  13. Launch Unity and open the your project. Note that Wwise Listeners are already attached to the Main Camera. Look at the hierarchy in Window > Wwise Picker to confirm that all of your Events are available here in Unity.
  14. Drag the MAIN SoundBank from Wwise Picker to the Player Game Object (or any other element that will persist throughout the game). Set Load On to Start and Unload On to Nothing.
  15. At this point matters get personal... Depending on what you need to do in your game there are many options to cue sounds that are meant to coincide with in-game events and actions.

To play a persistent sound, or to trigger on an in-game event you can often limit your work to the Unity Inspector. Select a Game Object in Unity, click Add Component in the object's Inspector, and define the following parameters:

Some solutions require additional work in code. To get Unity to communicate with Wwise in a more sophisticated manner, copy these code starters and paste into the C# files for your game.

Play Wwise Event (and the sound(s) it contains)

Play/cue a sound directly from a C# script. This approach makes no use of the Unity Inspector at all.

   // This line goes inside a function or other code block to cue the sound at the time it's needed    
   AkSoundEngine.PostEvent ("Sound_Event", gameObject);     

Play Wwise Event and Modulate an Associated Parameter

Play/cue the sound using the steps above. In addition, use this C# statement to modulate the RTPC time line of that sound using an in-game parameter.

Note the different parameter references progress_ge and Progress_MW:

   // This line goes inside a function like FixedUpdate() so that values are continuously updated    
   AkSoundEngine.SetRTPCValue ("Progress_MW",progress_ge,GameObject.FindGameObjectWithTag("Player"));  // send velocity value (progress_ge) to Wwise Engine as RTPC (Progress_MW) and modulate playback   

Control Interactive Music States

With Wwise most of the heavy lifting is done in the middleware tool: States are defined and paired with Switch Containers. With these elements in place, Unity "directs traffic" by cueing a State at the appropriate time.

   // This line should appear within the code block that is used to prompt a change or development in your music    
   AkSoundEngine.SetState ("State_Group_MW","State_Name_MW");

   // For example, if a player has initiated a new game, tell the Game_Music State Group to play the Intro_State state.
   if (GameStarted == true)
   {
      AkSoundEngine.SetState ("Game_Music","Intro_State");
   }

Related Resources

Musical Building Blocks: Wwise Wwise examples drawn from Composing Music for Games by Chance Thomas.

<