Can not load bank(.bytes) In Resources Files

Hi,

Thank you for taking those screenshots, they helped a lot!

You are missing one crucial step in getting this to work. A deeper explanation of each step can be found in the Unity Docs under Unity Integration | AssetBundles & Addressables.

First, select all your build FMOD text assets and assign them to a new AssetBundle. You can have as many differently named AssetBundles as you need to load in different banks when they are required.

Keep in mind the name you use, as it is required for the next step.

Once all your FMOD text assets have been assigned to an AssetBundle, even ones that will be loaded in later, then we need to build them using the example from the Docs:

BuildAssetBundles class
using FMODUnity;
using UnityEditor;
using UnityEngine;
// This #if statement will stop the function being compiled in build as we are using Editor only function calls
#if UNITY_EDITOR

public class BuildAssetBundles
{
    [MenuItem("Tools/Build Asset Bundles")]
    public static void StartProcess()
    {
        BuildTarget buildTarget = BuildTarget.StandaloneWindows64;

        EventManager.CopyToStreamingAssets(buildTarget);
         // The function's first parameter will be the file path where you want your AssetBundles to be built. In your case: Application.dataPath + "//Resources//Sound". However, it is a good idea to leave these in the `StreamingAsset` folder 
        BuildPipeline.BuildAssetBundles(Application.dataPath + "//Resources//Sound", BuildAssetBundleOptions.None, buildTarget);

        EventManager.UpdateBankStubAssets(buildTarget);
    }
};
#endif

This script will give us a new option on the Unity toolbar under Tools
image

When you click this option it should build all your FMOD text assets into Unity AssetBunldes in the destination folder. The destination folder will have to exist before the function is called.

Now we will need to load those AssetBundles like this:

LoadAllBanks class
using System.IO;
using UnityEngine;

public class LoadAllBanks : MonoBehaviour
{
    void Awake()
    {
       // This will need to be the same file path as where you are building the AssetBundles too.
        var assetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath + "/Resource/Sound", "banks"));
        if (assetBundle == null)
        {
            Debug.LogError("Failed to load AssetBundle!");
            return;
        }

        foreach (var name in assetBundle.GetAllAssetNames())
        {
            FMODUnity.RuntimeManager.LoadBank(assetBundle.LoadAsset<TextAsset>(name));
        }
        FMODUnity.RuntimeManager.StudioSystem.getBankCount(out int count);

        
        assetBundle.Unload(false);
    }
}

Now your banks should hopefully be loaded. Keep in mind that not all banks need to loaded in simultaneously. However, the Master.bytes and the Master.strings.bytes will need to be loaded first.

Hope this helps!

1 Like