Version

menu_open
Warning: you were redirected to the latest documentation corresponding to your major release ( 2022.1.17.8543 ). Should you wish to access your specific version's documentation, please download the offline documentation from the Audiokinetic Launcher and check the Offline Documentation option in Wwise Authoring.
Wwise Unity Integration Documentation
Using C# Code to Control the Sound Engine

Most Wwise SDK functions are available in Unity through the AkSoundEngine class. Think of it as the replacement of C++ namespaces AK::SoundEngine, AK::MusicEngine, and so on. See API Limitations for changes made in the API binding compared to the original SDK. For more complex situations, you'll need to call Wwise functions from code. In the API, the GameObjectID in all functions is replaced by the Unity flavor of the GameObject. At runtime, an AkGameObj component is automatically added to this GameObject, unless you have already manually added it before.

Using numeric IDs instead of strings for Events and Banks

The native Wwise API allows you to use strings or IDs to trigger events and other named objects in the Wwise project. You can still do this in the C# world by converting the file Wwise_IDs.h to Wwise_IDs.cs. Click Assets > Wwise > Convert Wwise SoundBank IDs. You need to have Python installed to make this work.

Sending MIDI to Wwise

MIDI can be sent to Wwise by filling the AkMIDIPost members of AkMIDIPostArray class and calling any of the following methods:

The following is a basic script that sends MIDI messages to the sound engine:

Offline Rendering in Unity

The Unity integration exposes the offline rendering feature within the Wwise SDK and simplifies how audio samples can be retrieved.

Caution: Care must be taken to ensure that only the asynchronous AkSoundEngine.LoadBank and AkSoundEngine.UnloadBank APIs are used from the main thread when offline rendering is enabled. See Custom Scheduling of Audio Rendering for details.

AkSoundEngine.StartDeviceCapture sets up a specific output audio device for capture so that the number of available samples can be determined by calling AkSoundEngine.UpdateCaptureSampleCount and the audio samples can be retrieved by calling AkSoundEngine.GetCaptureSamples.

The following example illustrates how to use the Unity integration to perform offline audio rendering in conjunction with Unity's screen capture functionality. With this functionality implemented, one can easily perform a multiplexing post-processing step to combine the captured audio samples and video frames into a movie.

Using the Audio Input Source Plug-in in Unity

The audio input source plug-in can be used via C# scripting. See Audio Input Source Plug-in from the Wwise SDK documentation.

The following is a basic script that sends a test tone to the audio input source plug-in:

Apply Custom Positioning in Unity

By default, the AkGameObj component is attached to a specific Unity gameObject and uses its transform (with an optional offset) for full positioning. This is usually adequate for many games, such as first-person shooters. However, games with custom camera angles, such as many third-person games, may find it difficult to accommodate the two aspects of positioning (distance attenuation and spatialization) by simply attaching the audio listener to one game object, such as the main camera in Unity. Other games may want players to experience other custom positioning.

To this end, the AkGameObj component class provides overridable positioning to Unity users. Through the three virtual methods GetPosition(), GetForward(), and GetUpward(), users can derive a subclass from AkGameObj and use that subclass component to customize any number of Unity gameObjects' positioning.

Here is a simple example of how to use a custom component to override the default AkAudioListener behavior. With a third-person project integrated with Wwise, remove the existing AkAudioListener and its associated AkGameObj. Then attach the following script to the MainCamera object, attach AkAudioListener, and finally specify the target Unity gameObject (such as the player avatar) that the audio listener's position will follow. After this, the distance attenuation of all the emitters will rely on the selected target Unity gameObject's position as the listener position (an on-screen distance listener), while the orientation of all the emitters is still based on the main camera orientation as the listener orientation (an off-screen orientation listener).

Definition: AkWwiseAcousticTexture.cs:21
This type can be used to post Events to the sound engine.
Definition: AkWwiseEvent.cs:29
This component represents a sound object in your scene and tracks its position and other game syncs s...
Definition: AkGameObj.cs:32
Definition: AkWwiseAcousticTexture.cs:21
virtual UnityEngine.Vector3 GetPosition()
Definition: AkGameObj.cs:272

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise