Before addressables i think i used Bank loader mono. It worked fine, and fast.
So I wanted to switch to addressables because I want to load banks and audio tables from remote yet the problem starts without even remote banks being loaded. All loading banks below are local!
I switched to proper import type for .bytes and strings.bytes.
I’m trying to load using Addressable Asset Databse option. Works fine.
I’m switching to Use build. Now LoadBank Master.bytes hangs main thread and loads the same banks for like 5 seconds.
There is no logs when it hangs.
Why IDK. I tested different groups etc to no effect.
I still use loading .strings with LoadBank. Since it doesn’t hang.
I found out it’s default blocking. Maybe issue? I guess it somehow was non blocking when I didn’t use Addressables?
There is no API for loading bank with non blocking so i have to dig…
Ok so I’m switching out the LoadBank to loading in memory. RuntimeManager.StudioSystem.loadBankMemory
Now loads in two frames my master bank.
Ok solution solved? Well not yet
Well It works using Use Existing Build but then I switch to Asset database and more errors.
This is using AssetDatabase.
I don’t want to go back to Runtime.LoadBank if it means having to wait 5 seconds every press play.
Solution?
unity 6000.1.6f
private async UniTask<bool> load_bank_from_asset_reference_non_blocking(AssetReference bankAssetRef, CancellationToken token)
{
AsyncOperationHandle<TextAsset> handle = default;
if (bankAssetRef == null)
return false;
try
{
handle = bankAssetRef.LoadAssetAsync<TextAsset>();
await handle;
if (token.IsNullOrCanceled()) return false;
Log.NoST($"[AudioManager] Loaded bank TextAsset from AssetReference. {bankAssetRef.Asset.name}");
if (handle.Status != AsyncOperationStatus.Succeeded || handle.Result == null)
{
Debug.LogError($"Failed to load Addressable TextAsset for {bankAssetRef.RuntimeKey}. Status: {handle.Status}");
return false;
}
else
{
// NONBLOCKING
Bank bank;
var res = RuntimeManager.StudioSystem.loadBankMemory(handle.Result.bytes, LOAD_BANK_FLAGS.NONBLOCKING, out bank);
if (res != FMOD.RESULT.OK)
{
Debug.LogError($"FMOD loadBankMemory returned {res} for {bankAssetRef.RuntimeKey}");
return false;
}
LOADING_STATE state;
do
{
if (token.IsNullOrCanceled())
{
// unload bank to avoid partial resource leaks
try
{
bank.unload();
}
catch (Exception e)
{
Debug.LogWarning($"Exception unloading bank on cancel: {e}");
}
return false;
}
bank.getLoadingState(out state);
#if UNITY_EDITOR
Log.NoST($"[AudioManager] Loading bank to memory... {bankAssetRef.Asset.name}");
#endif
await UniTask.Yield();
} while (state == LOADING_STATE.LOADING);
if (state == LOADING_STATE.LOADED)
{
Log.NoST($"[AudioManager] Bank loaded from Addressables! {bankAssetRef.Asset.name}");
}
else
{
Debug.LogError($"Bank loading ended in state {state} for {bankAssetRef.RuntimeKey}");
// Unload to be safe
try
{
bank.unload();
}
catch
{
Debug.LogWarning($"Exception unloading bank on error: {bankAssetRef.RuntimeKey}");
}
}
}
}
finally
{
if (handle.IsValid())
Addressables.Release(handle);
}
return true;
}