Lesson 3

Table of Contents

Loading SoundBanks using Triggers

In the Wwise Adventure Game, the game content is separated into progress (like 'active quest') and regions (like desert or dungeon). This means that when the Player located in the Woodlands, the SoundBank containing the Waterfall Event will be loaded into memory, ready to be posted. Once the Player is outside that region and the Event is stopped, the SoundBank with the Waterfall Event can be unloaded from memory, releasing memory for other SoundBanks to be loaded.

To register that the AkAudioListener is entering a region like the Woodlands, you can use a Trigger.


To learn more about Trigger Colliders, please refer to Lesson 1.

On the Main Camera (the game object with the AkAudioListener component), you'll find a Sphere Trigger Collider. When this Trigger Collider enters a region Trigger Collider, the SoundBank of that region should load using the AkBank script. In the following steps, we'll set up a game object with a Cube Collider set to Is Trigger for the Woodlands Region, and from it load the Woodlands Soundbank using the AkBank script.

  1. In the Unity menu, go to Audiokinetic > Certification > 301 > Lesson 3 and select Loading SoundBanks using Triggers.

    In Unity, you have various types of Colliders at your disposal. For the Woodlands region, you will scale a Box Trigger to fit the region spanning from the Village bridge all the way to the Cave. First of all, let's adjust the Scene view to look at the Woodlands area.

  2. In the Hierarchy, select the Waterfall game object and, with the mouse inside the Scene view, click F.

  3. In the Unity menu, go to GameObject > 3D Object and select Cube.

    For convenience, let's give the game object a more appropriate name that describes its functionality.

  4. Right-click the Cube game object, select Rename, and enter 'Woodlands Trigger'.

    When you created the Cube game object, a Box Collider was automatically added to the game object. The Box Collider has several property fields, like the Size (relative to the game object's scale), the Center of it (relative to its pivot point), the physical Material (used to define physical properties like friction), and topmost the Is Trigger property, which will allow other Colliders to enter its Collider shape (described more in detail in Lesson 1). The Woodlands Trigger is supposed to be a Collider shape you can enter and exit with the Player, so let's set it to being a Trigger.

  5. In the Inspector, locate the Box Collider and enable Is Trigger.

    As other Colliders can enter the Box Collider, one should eventually make the Mesh of the Collider invisible; however, let's first make it into a transparent material while developing, so you can see when you are entering the Trigger. You can use a premade Trigger_Red material, which is a Shader (code used to define shape and color) set to transparent red.

  6. In the Project view, search for Trigger_Red.

  7. Drag the Trigger_Red Material from the Project window onto the created Woodlands Trigger game object in the Hierarchy.

    You will now be able to see the exterior of the Collider as a transparent red, but note that you cannot see the shape while positioned inside of it.

    Next, you need to adjust the Trigger Collider to fit the Woodlands region, which spans from the Village to just before the Cave. For that you'll use the Move tool, Rotate tool, and Scale tool.


    It's advised not to use the combined tool - 'Move, Rotate or Scale', but instead start by getting familiar with the individual Move, Rotate, and Scale tools.

    Use the Scale tool to enlarge the game object.

  8. In the Unity Toolbar, select the Scale tool.

  9. Click and hold the center gray box and drag the mouse to the right until the box is higher than the Trees.

  10. Use the Move tool, Rotate tool, and Scale tool to make the last adjustments to the game object, so that it covers the entire Woodlands region.

    The Collider can cover adjacent areas, like parts of the Pine Forest, but make sure to align the Village facing side to slightly covering the bridge and no further, as this is where the Village Trigger is loading the Village SoundBank and all Events in the Woodland SoundBank should stop. Next, we'll add the AkBank script so that the Woodlands SoundBank is loaded when the Player enters the Box Collider.

  11. Make sure you have the Woodlands Trigger game object selected and, in the Inspector, click Add Component, search for AkBank, and select the script.

    Now let's assign a SoundBank.

  12. In the Bank Name property, expand Banks > Default Work Unit > Region and select Woodlands.

    Next, let's set it to AkTriggerEnter, to detect whether the Trigger is being entered by another Trigger.


    As described in Lesson 1, when needing to change the condition of when to load the SoundBank, you need to first set it to Nothing and then the new Load option, so you won't have both options selected.

  13. Set the Load On property to AkTriggerEnter only.

  14. Set the Unload On property to AkTriggerExit only.

    You have now set the Woodlands SoundBank to load on entering and unload when exiting the Collider; however, you have not specified what game object it should detect. This means that everything entering or exiting the Trigger will be detected, including the ground Collider, Evil Crawlers, and so on. As only the listener (Main Camera) should be detected when entering, we will need to add the AkTriggerEnter script and assign a Trigger Object.

  15. In the Inspector, click Add Component, then search for AkTriggerEnter and select it.

  16. From the Hierarchy, drag the Main Camera game object into the the AkTriggerEnter's Trigger Object property.

  17. In the Inspector, click Add Component, then search for AkTriggerExit and select it.

  18. From the Hierarchy, drag the Main Camera game object into the AkTriggerExit's Trigger Object property.

    You have now performed all the necessary steps to load and unload a SoundBank on entering and exiting a Trigger, respectively. Good practice is to always test your implementations, so let's connect the profiler to the game in runtime.

  19. In Wwise, click Remote…

  20. In the Remote Connections window, highlight the Wwise Adventure Game (Editor) and click Connect.

  21. In Unity, click Play.

  22. Run to the Woodlands.

  23. Click Play again and exit Play mode.

  24. In the Wwise menu, go to Layouts and select Profiler.

  25. Drag the time cursor backwards until you see the Woodlands SoundBank in the Advanced Profiler's Memory tab.

Notice that the Woodlands SoundBank is loaded once you enter the Woodlands region, but if you drag the time cursor even further left, the Woodlands.bnk will at some point not show, meaning it's loaded later in the playthrough when the player enters the Woodlands Trigger.