Null references loading banks from Unity AssetBundles in Android build

Hello,

We are getting null reference exceptions when calling RuntimeManager.LoadBank() on Android builds. Most curiously, the bank loading works fine if I switch to Streaming Assets as our Import Type in the FMOD settings, however, it will not work when using Asset Bundles, which is what we want to use for our architecture (this approach is already working on iOS, desktop, and in editor with the Android simulator)

RuntimeManager.LoadBank() is executed asynchronously within an Awaitable as follows:

                //Banks is a List<string> that defines all of our bank names
                foreach (var bank in Banks)
                {
                    Debug.Log("Load bank:" + (bank as string));
                    
                    RuntimeManager.LoadBank(bank, true);
                }

                Debug.Log("Begin waiting.");

                // Keep yielding the until all the bank loading is done
                // (for platforms with asynchronous bank loading)
                while (!FMODUnity.RuntimeManager.HaveAllBanksLoaded)
                {
                    //Debug.Log("Wait.");
                    await Awaitable.NextFrameAsync();
                }

Unity version: 2023.2.5f1
FMOD version: 2.02.19
We have Split Application Binary set to true in our Project Settings

Here is one copy of the error from trying to load one of the banks:

2024/04/01 15:19:00.058 15941 15962 Error Unity NullReferenceException: Object reference not set to an instance of an object.
2024/04/01 15:19:00.058 15941 15962 Error Unity   at FMOD.Studio.System.loadBankMemory (System.Byte[] buffer, FMOD.Studio.LOAD_BANK_FLAGS flags, FMOD.Studio.Bank& bank) [0x00000] in <00000000000000000000000000000000>:0 
2024/04/01 15:19:00.058 15941 15962 Error Unity   at FMODUnity.RuntimeManager+<loadFromWeb>d__57.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
2024/04/01 15:19:00.058 15941 15962 Error Unity   at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <0000000000
 (302.6 KB)
0000000000000000000000>:0 

Here is a text file of the Android Log cat from trying to run the build with Enable API Error Logging on and Logging Level set to “Log”. This created a lot of new errors that I wasn’t receiving before enabling logging. I believe they are only happening because our general API stack is falling apart from failing to load the banks (which is our core problem).

fmodandroidlog.txt

Thank you!

If you are using AssetBundles then you will need to handle loading the asset, using the AssetBundle api, before loading the bank using LoadBank(TextAsset asset) instead of the string version of LoadBank.

See our documentation on Using AssetBundles.