Can not load bank(.bytes) In Resources Files

I can not load bank in Android device. That bank file include to Resources File.

I was setting FMOD Import Type AssetBundle, because i use addreassable.
When Importing FMOD banks in FMOD Asset Sub Folder path, And then i copyied one of them(master.assets.bytes,master.bytes, …etc) to Resource Folder.
Why i use the banks file in Resources Folder, because i need to play some BGM sound before download ing bank files from addressable.

so, i got a error logcat in android device (ERR_FORMAT). see below the error

07-18 19:21:46.570: E/Unity(17261): BankLoadException: [FMOD] Could not load bank 'Master.assets' : ERR_FORMAT : Unsupported file or audio format.
07-18 19:21:46.570: E/Unity(17261):   at FMODUnity.RuntimeManager.LoadBank (UnityEngine.TextAsset asset, System.Boolean loadSamples) [0x00000] in <00000000000000000000000000000000>:0 
07-18 19:21:46.570: E/Unity(17261):   at SoundSample.Start () [0x00000] in <00000000000000000000000000000000>:0 

please help to this prorblem.

you can check my code and setting things below the screenshots.

//this is my code

//this is my editsetting

//this is bytesfiles in FMOD Asset Sub Folder path

//this is bytes files that load bank in Resources folder path

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

Thanks to anwser.
But you miss that i said use addressable, not use the assetBundle.
please guide for me again that addressable

My apologies I missed that, to use Addressables follow this example:

  1. We need to ensure we have defined UNITY_ADDRESSABLES_EXIST in the player settings. This can be found under Unity Toolbar → Edit → Project Settings → Player → Other Settings → Script Compilation. You may get some errors in the console but that is fine, they will be solved in the next step.

  2. Import the Addressable Package from the Unity Asset Manager Window under Unity Toolbar → Window → Package Manager → Unity Registry → Addressables.

Package Manager

  1. Assign the FMOD Text Assets to Addressables, you can do this by selecting them in your Project Directoy and ticking the Addressable tick box
  2. The Addressables will want to be loaded into memory `Asyn
  3. Now the Addressables are ready to be loaded into memory. Create a new script named LoadAllBanks and then copy the following example into that script. You can change the name if you like.
LoadAllBanks class
	Using UnityEngine; 
	using System;
	using System.Collections.Generic;
	using UnityEngine.AddressableAssets;
	using System.Collections;
	using UnityEngine.SceneManagement;
	
	public class LoadAllBanks : MonoBehaviour
	{
	    public List<AssetReference> Banks = new List<AssetReference>();
	    public string Scene;
	
	    private static int numberOfCompletedCallbacks;
	
	    void Awake()
	    {
	        StartCoroutine(LoadBanksAsync());
	    }
	
	    private Action Callback = () =>
	    {
	        numberOfCompletedCallbacks++;
	    };
	
	    IEnumerator LoadBanksAsync()
	    {
	
	        Banks.ForEach(b => FMODUnity.RuntimeManager.LoadBank(b, true, Callback));
	
	        while (numberOfCompletedCallbacks < Banks.Count)
	            yield return null;
	
	        while (FMODUnity.RuntimeManager.AnySampleDataLoading())
	            yield return null;
	
	        AsyncOperation async = SceneManager.LoadSceneAsync(Scene);
	
	        while (!async.isDone)
	        {
	            yield return null;
	        }
	
	        Banks.ForEach(b => b.ReleaseAsset());
	    }
	}
  1. In the Inspector window of an object with your script, add the banks you wish to load
    image

  2. Loading Unity assets are an Asynchronous operation, further explanation can be found in Unity | Getting started with Addressable Assets, so we will need an empty scene to load the banks then a populated scene to play them in. So in your Unity Build Settings you will want to have something like this:
    image
    In the EmptyScene is our object that loads our banks, then we transition to the MusicScene where we will hear our events.

  3. Make sure to start the project in the EmptyScenetoLoadBanks, now all the assigned banks should be loaded

Sorry about the confusion, I hope this helps!

1 Like