# Unity Addressable Loading Banks

**URL:** <https://qa.fmod.com/t/unity-addressable-loading-banks/21754>\
**Category:** Unity\
**Created:** [June 12, 2024, 12:06am UTC](https://qa.fmod.com/t/unity-addressable-loading-banks/21754 "2024-06-12T00:06:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.wasilenko](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@justin.wasilenko](https://qa.fmod.com/u/justin.wasilenko)\
**Post date:** [June 12, 2024, 12:06am UTC](https://qa.fmod.com/t/unity-addressable-loading-banks/21754/1 "2024-06-12T00:06:17Z")

</div>

I am trying to load my banks using Addressables but not getting anywhere. The documentation isn’t quite clear on this, but I am trying to load what I think you guys call stub files? It’s not clear to me how these text files point to the .bank files that I think I should be loading.

When I do I keep getting this error:

```auto
[FMOD] assert : assertion: 'mRiffChunk.mType == ChunkType_Riff && mRiffChunk.mID == id' failed
Failed to load Master.bank with error: ERR_FORMAT

```

Down below is a copy of my code.

```auto
 public class AudioMixer : MonoBehaviour
  {
    #region Fields

    public static AudioMixer Instance => _instance;
    private static AudioMixer _instance;
    private const string MasterBankKey = "FMODBanks/Master.bytes";

    public AssetReference MasterBank;
    public AssetReference MasterStringBank;
    public List<AssetReference> Banks;

    public bool PreloadSamples;

    #endregion

    #region Methods

    private void OnEnable()
    {
      Load();
    }

    private void Awake()
    {
      if (_instance == null)
      {
        _instance = this;
        InitializeFMODSystem();
        // StartCoroutine(LoadMasterBank());
      }
      else
      {
        Debug.LogWarning("AudioMixer instance already exists!");
        Destroy(this);
      }
    }

    private void Start()
    {
      RuntimeUtils.EnforceLibraryOrder();
    }

    private void InitializeFMODSystem()
    {
      FMOD.Studio.System system = RuntimeManager.StudioSystem;
      if (!system.isValid())
      {
        Debug.LogError("Cannot get FMOD.Studio.System instance!");
        return;
      }
    }

    public void Load()
    {
      foreach (var bankRef in Banks)
      {
        try
        {
          RuntimeManager.LoadBank(bankRef, PreloadSamples);
        }
        catch (BankLoadException e)
        {
          RuntimeUtils.DebugLogException(e);
        }
      }

      RuntimeManager.WaitForAllSampleLoading();
    }

    private IEnumerator LoadMasterBank()
    {
      AsyncOperationHandle<TextAsset> handle = MasterBank.LoadAssetAsync<TextAsset>();
      yield return handle;

      if (handle.Status == AsyncOperationStatus.Succeeded)
      {
        var bankTextAsset = handle.Result;
        Debug.Log("Loaded TextAsset for Master.bank with size: " + bankTextAsset.bytes.Length);
        FMOD.RESULT result = RuntimeManager.StudioSystem.loadBankMemory(bankTextAsset.bytes, LOAD_BANK_FLAGS.NORMAL, out Bank bank);
        if (result == FMOD.RESULT.OK)
        {
          Debug.Log("Successfully loaded Master.bank");
        }
        else
        {
          Debug.LogError("Failed to load Master.bank with error: " + result);
        }

        // Addressables automatically handle releasing the asset
      }
      else
      {
        Debug.LogError("Failed to load Master.bank addressable");
      }
    }

```

I would love to see how someone setup their project and an example on how they load banks using Addressables.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 17, 2024, 2:53am UTC](https://qa.fmod.com/t/unity-addressable-loading-banks/21754/2 "2024-06-17T02:53:05Z")

</div>

Hi,

Thank you for this script. I was not able to load events with it however.

> [@justin.wasilenko](#):
>
> The documentation isn’t quite clear on this, but I am trying to load what I think you guys call stub files?

Correct, they are text files that contain stub data for loading the source bank. When using addressable, however, we are trying to load them as `AssetReferences`.

Please set logging to level `Log` in the FMOD settings  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/c/c3e4fb61e2897180d34f138a22485c16c4f977ba.png)  
and let me know if there are FMOD errors logged in the console.

The issue may be trying to play events before the banks have been loaded. The solution may be loading the banks in a different scene than the one playing the events.

I have slightly modified the Asynchronous Loading example script to work with Addressables:

> **Addressables Async Loading**
>
> ```auto
> using UnityEngine;
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine.SceneManagement;
> using UnityEngine.AddressableAssets;
> 
> class ScriptUsageLoading : MonoBehaviour
> {
> public List<AssetReference> Banks = new List<AssetReference>();
> 
> // The name of the scene to load and switch to
> public string Scene = null;
> 
> public void Start()
> {
> StartCoroutine(LoadGameAsync());
> }
> 
> void Update()
> {
> // Update the loading indication
> }
> 
> IEnumerator LoadGameAsync()
> {
> // Start an asynchronous operation to load the scene
> AsyncOperation async = SceneManager.LoadSceneAsync(Scene);
> 
> // Don't let the scene start until all Studio Banks have finished loading
> async.allowSceneActivation = false;
> 
> // Iterate all the Studio Banks and start them loading in the background
> // including the audio sample data
> foreach (var bank in Banks)
> {
> FMODUnity.RuntimeManager.LoadBank(bank, true);
> }
> 
> // Keep yielding the co-routine until all the bank loading is done
> // (for platforms with asynchronous bank loading)
> while (!FMODUnity.RuntimeManager.HaveAllBanksLoaded)
> {
> yield return null;
> }
> 
> // Keep yielding the co-routine until all the sample data loading is done
> while (FMODUnity.RuntimeManager.AnySampleDataLoading())
> {
> yield return null;
> }
> 
> // Allow the scene to be activated. This means that any OnActivated() or Start()
> // methods will be guaranteed that all FMOD Studio loading will be completed and
> // there will be no delay in starting events
> async.allowSceneActivation = true;
> 
> // Keep yielding the co-routine until scene loading and activation is done.
> while (!async.isDone)
> {
> yield return null;
> }	
> }
> }
> 
> ```

Add this to an empty scene and add all the banks that you will need. Then your main scene containing the event emitters and it should load successfully.

Hope this helps, if you have any other issues please do not hesitate to ask!
