Version

menu_open
Warning: you were redirected to the latest documentation corresponding to your major release ( 2023.1.9.8628 ). 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
Basic Tutorial For Packaging DLC

This example demonstrates how to separate certain assets (such as new items or characters) into a DLC asset bundle that is packaged using Addressables.

Prerequisites

Before you proceed with this tutorial, do the following:

Installing the Addressables Demo Scene

An Addressables Demo Scene is available on GitHub.

To install the Addressables Demo Scene:

  1. In a browser, open https://github.com/audiokinetic/WwiseUnityAddressablesDemoScene.
  2. Clone the repository to your computer.
  3. In the Unity Editor, open the WwiseDemoScene.
  4. Select Window > Package Manager.
  5. Click + and select Add package from disk.
    Warning: Do not select Add package from git URL. If you install the package that way, you cannot open the sample scenes.
  6. Open the package.json file in the WwiseUnityAddressablesDemoScene repository.

Getting Started

For this tutorial we have created two sound effects, an event and a SoundBank in the Wwise project.

We created two GameObject prefabs with AkBank and AkEvent components : DlcAssetHighImpact and DlcAssetLowImpact. These prefabs load the DLC SoundBank and play a sound effect when they are instantiated.

We also created two scenes: AddressablesDemoScene and AddressablesSubScene. AddressablesDemoScene is a simple Unity scene with some interactive buttons so we can test loading and unloading our Addressable assets. AddressablesSubScene is a scene containing only the DlcAssetLowImpact prefab. We will use it to test loading scenes containing Wwise objects with Addressables.

Note:The AddressablesDemoScene also contains an example of using localized voices and changing languages with the Wwise Addressables package.

All of these assets, as well as the scripts described in the following section, are found in the WwiseUnityAddressablesDemoScene package.

Mark the three following assets as addressable by enabling the Addressable checkbox in their inspector:

  • AddressablesSubScene.unity
  • Prefabs/DlcAssetHighImpact.prefab
  • Prefabs/DlcAssetLowImpact.prefab
Caution: Removing the Unity Addressables package from your project will remove the Addressable field from all assets and the state of this check box will not be preserved if you reinstall the package.

In the Addressables Groups window, you will find that these Addressable assets have been placed by default in the Default Local Group.

New groups can be created by either right-clicking the groups window and selecting Create New Group, or from the menu New > Packed Assets. Create two new groups for the DLC assets:

  • DLC_Assets for our prefabs and subscene.
  • DLC_WwiseData_Windows for our platform specific Soundbank assets.
Note:In this example we only create one additional SoundBank group for the Windows platform, but in general you should create one for each platform you plan on deploying to.
  • Move the DlcAssetHighImpact, DlcAssetLowImpact and AddressablesSubScene from the Default Local Group to the DLC_Assets group.
  • Move the platform specific DLC SoundBank asset from WwiseData_Windows to the DLC_WwiseData_Windows group.
Note:
  • We made sure to include the strings WwiseData and the platform name Windows in the platform specific group name, so that it will be properly handled by the BuildWwiseData script when building Addressables.
  • To save your group modifications, run the Assets > Wwise > Addressables > Serialize addressable asset metadata action once with the Use Sample Metadata Preserver setting enabled.

In the Groups window, set the Play Mode Script to Use Existing Build and build the new Addressable packages with the Wwise Build Script (as described in Building the Project).

Now, open the AddressablesDemoScene.

Loading Assets with Addressables

In this scene there are two buttons

  • The button on the left loads and instantiates the DlcAssetHighImpact prefab using Addressables.
  • The button on the right loads and instantiates the AddressableSubScene.
    • This scene contains the DlcAssetLowImpact asset.

If you inspect the Loading DLC Assets Demo GameObject, you will see that we have created an AssetLoader object, which contains the AddressablePrefabLoader component.

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class AddressablePrefabLoader : MonoBehaviour
{
public AssetReference reference;
public void Load()
{
Addressables.LoadAssetAsync<GameObject>(reference).Completed += asyncOp =>
{
if (asyncOp.Status == AsyncOperationStatus.Succeeded)
{
Instantiate(asyncOp.Result,this.transform);
}
};
}
}

This component contains an AssetReference, which we have set to be the DlcAssetHighImpact prefab in its inspector.

When we run the game and press the left button, the Load method on the AddressablePrefabLoader will be called, loading it from the DLC_Assets and instantiating the DlcAssetHighImpact prefab. Once instantiated, the AkBank component will load the SoundBank from the DLC_WwiseData_Windows asset bundle.

Loading Scenes with Addressables

If you inspect the Loading DLC Scene Demo GameObject, you will see that we have created a SceneLoader object, which contains the AddressableSceneLoader component.

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
public class AddressableSceneLoader : MonoBehaviour
{
public AssetReference scene;
private AsyncOperationHandle<SceneInstance> sceneHandle;
public void Awake()
{
DontDestroyOnLoad(gameObject);
}
public void LoadScene()
{
if (!sceneHandle.IsValid() )
{
scene.LoadSceneAsync( LoadSceneMode.Additive).Completed += SceneLoadComplete;
}
else
{
UnloadScene();
}
}
public void UnloadScene()
{
Addressables.UnloadSceneAsync(sceneHandle).Completed += op =>
{
if (op.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log("Successfully unloaded scene");
}
};
}
private void SceneLoadComplete(AsyncOperationHandle<SceneInstance> obj)
{
sceneHandle = obj;
if (obj.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log(obj.Result.Scene.name + " successfully loaded");
}
}
}

This component uses an AssetReference to hold a reference to our AddressablesSubScene. The first time the button is pressed, the LoadSceneMethod is called, which will load the scene using the LoadSceneAsync method and add it to our current scene. The second time the button is pressed, the scene will be unloaded.

The AddressablesSubScene only contains our DlcAssetLowImpact prefab, which upon instantiation will load the DLC soundbank and play its corresponding event.

Changing Languages

The third demo in this scene lets you switch between the English and French languages and play a localized voice sample. This demo uses the AkWwiseSetLocalization script. Upon pressing the green or blue buttons, this calls the AkAddressableBankManager.SetLanguageAndReloadLocalizedBanks function to change the language to English or French.

This function performs the following operations:

  • Unload all localized banks
  • Unload the Init bank
  • Set the language using AkSoundEngine.SetCurrentLanguage
  • Reload the Init bank
  • Reload the localized banks
using UnityEngine;
public class AkWwiseSetLocalization : MonoBehaviour
{
public string LanguageString;
public void SetLanguage()
{
Debug.Log($"Setting language to {LanguageString}");
AK.Wwise.Unity.WwiseAddressables.AkAddressableBankManager.Instance.SetLanguageAndReloadLocalizedBanks(LanguageString);
}
}

You can now build the AddressablesDemoScene and test the buttons to ensure that your built game is loading these assets.

Setting Up Addressables Hosting

Now we will configure Unity to serve our addressable DLC assets using its built-in hosting service. This will allow us to test updating assets using Addressables, without rebuilding our player.

First, build the AddressablesDemoScene and ensure that it works as expected. In the build window, you will have to add the AddressablesDemoScene with the Add open scenes button and select it as the scene to build.

Next we will configure Addressables Hosting, which can be accessed from the Tools menu.

Now create a Local Hosting service and enable it by selecting the Enable check box.

Open the Addressables Profiles window through the menu (Profile > Manage Profiles) and create a new profile named Editor Hosted.

Set Local and Remote. Then set the Paths to the following :

  • Local.BuildPath : HostedData/[BuildTarget]
  • Local.LoadPath : http://[PrivateIpAddress]:[HostingServicePort]
  • Remote.BuildPath : HostedData/[BuildTarget]
  • Remote.LoadPath : http://[PrivateIpAddress]:[HostingServicePort]

Then, use this profile by right-clicking Editor Hosted and selecting Set Active.

Note:Consult the official documentation for more information about using Addressables hosting service.

Inspect the DLC_WwiseData_Windows group asset and ensure that its Build & Load Paths have been updated.

Open your Addressable Asset Settings and enable Build Remote Catalog. Set the Build & Load Paths to Local.

Rebuild your addressable assets using the Wwise Build Script. The new adressable AssetBundles should be created in <Unity Project Path>\HostedData.

Now rebuild the AddressablesDemoScene to test that your assets are being served properly.

Open the Addressables Hosting window to view incoming requests as you run the game. The first time a button is pressed, a request should appear in the events log at the bottom of the window.

Updating an Addressables Asset

Now, we will update our DlcAssetHighImpact sound using Addressables.

First, in Wwise, adjust the imp_axe_stone_high sound sample's pitch value so that the change will be obvious. Then regenerate your SoundBanks.

Then, in the Addressables Groups window, select Build >Update a previous build. In the selection window that opens, select the addressables_content_state.bin file in AddressableAssetsData/Windows.

Finally, run your built game again (without rebuilding it). When it opens, you shoud see a request for the update catalog in the Addressables hosting window.

Then, when you press the left button, you should hear the sound effect at its new pitch height.

For more infomation about the Addressables catalog and the intended development cycle, consult the official documentation.

Note:This scripts provided in this tutorial are the minimum required to test loading assets with Addressables. You will likely want to use a more robust solution for loading assets in your project. Some more advanced examples can be found in the Unity Addressables Sample repository.
Definition: AkWwiseAcousticTexture.cs:21
Definition: AkWwiseAcousticTexture.cs:21

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