Version
Wwise Unity Integration Documentation
|
In this example we will show how to handle the simple situation where we want to separate some assets (for example a new item or character) into their own DLC asset bundle that is packaged using Addressables.
If you have not setup the Wwise Unity addressables package in you project, please follow consult the Installing the Wwise Unity Addressables Package.
The official repository for the Addressables Demo Scene used in this tutorial is https://github.com/audiokinetic/WwiseUnityAddressablesDemoScene. The demo scene uses assets that are found in the WwiseDemoScene so it must be installed first through the Audiokinetic Launcher.
Steps:
Note: | This package cannot be added using Add package from git URL as this type of installation will prevent you from opening the scenes contained in the package. |
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:
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:
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. |
Note: |
|
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.
In this scene there are two buttons
If you inspect the Loading DLC Assets Demo GameObject, you will see that we have created an AssetLoader object, which contains the AddressablePrefabLoader component.
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.
If you inspect the Loading DLC Scene Demo GameObject, you will see that we have created a SceneLoader object, which contains the AddressableSceneLoader component.
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.
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:
You can now build the AddressablesDemoScene and test the buttons to ensure that your built game is loading these assets.
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 :
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.
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. |
Des questions ? Des problèmes ? Besoin de plus d'informations ? Contactez-nous, nous pouvons vous aider !
Visitez notre page d'AideEnregistrez votre projet et nous vous aiderons à démarrer sans aucune obligation !
Partir du bon pied avec Wwise