Asset Bundle Loading Issue

Unity Editor version: 6.3 LTS
ML2 OS version:1.12.1
Unity SDK version:2.6.0
Host OS: (Windows/)

Error messages from logs: No error log.
Hi all,
I was previously loading my asset bundles without any problem with that piece of code;

`public async UniTask AsyncGenericBundleLoaderAndroid(string targetAssetName, string targetAssetBundleName)
where T : class
{
try
{

    var targetAssetBundle = _loadedAssetBundles
        .FirstOrDefault(x => string.Equals(x.Key, targetAssetBundleName, StringComparison.OrdinalIgnoreCase));

    if (targetAssetBundle.Key == null)
    {
        string bundlePath = string.Empty;
        bundlePath = Path.Combine(Application.streamingAssetsPath, targetAssetBundleName.ToLower());

        
        UnityWebRequest webRequest = UnityWebRequestAssetBundle.GetAssetBundle(bundlePath);
        await webRequest.SendWebRequest().ToUniTask();
        if (webRequest.result != UnityWebRequest.Result.Success)
        {
            Debug.LogError($"Could not load {targetAssetBundleName} assetbundle.WebRequest Error: {webRequest.error}");
            return null;
        }

        AssetBundle loadedAssetBundle = DownloadHandlerAssetBundle.GetContent(webRequest);
        if (loadedAssetBundle == null)
        {
            return null;
        }


        _loadedAssetBundles[targetAssetBundleName] = loadedAssetBundle;
    }

    // Retrieve the asset bundle from the dictionary
    var getAsset = _loadedAssetBundles
        .FirstOrDefault(x => string.Equals(x.Key, targetAssetBundleName, StringComparison.OrdinalIgnoreCase));
    AssetBundle assetBundle = getAsset.Value;


    var assetRequest = assetBundle.LoadAssetAsync<T>(targetAssetName);
    await assetRequest;
    return assetRequest.asset as T;
}
catch (Exception e)
{
    Debug.LogError($"Error On Bundle Loader {targetAssetName}, {targetAssetBundleName} {e.Message}");
    return null;
}

}`

now assetbundles are loading very slowly. It still loads, but takes around 20 ~ 30 secs to load my asset bundles. It was like 1-2 seconds to load the same thing. Would it be related to Magic Leap SDK ? or unity version ? Or if there is a special setting for build that I need to make? for example Texture Compression does not seem to work

Even if I select two Compression formats I’ll also need to make it an app bundle instead of an apk, which does not work with Magic Leap. Does anyone have another suggestion for this problem?
Thank you.

Hey @brs_kes ,

This is due to multiple changes with Unity 6 versions that affect loading times, specifically with Android builds.

The ML2 expect texture compression format ASTC. Any other texture format will take extra time to load/convert. So please try to only use ASTC if possible.

Another thing to try is explicitly set the BuildAssetBundleOptions to ChunkBasedCompression when building your asset bundles. This should reduce load times all around.

When building AssetBundles, explicitly set:

BuildAssetBundleOptions.ChunkBasedCompression

Example:

BuildPipeline.BuildAssetBundles(
    outputPath,
    BuildAssetBundleOptions.ChunkBasedCompression,
    BuildTarget.Android
);

If you need more tips or insight please let me know!

Best,
Corey

Yes I can confirm that my Assets are ChunkBased
and here is my android build setting I made Texture Compression ASTC didn’t see any difference it tooks a while to load.. :frowning:

Well, it’s not a solution, I should say it’s a total workaround. I had to downgrade my project, it was a big change, and I rolled back to 2022.3.61. I’m hoping that the problem will be solved because I really had to downgrade other things, like the burst compiler. AR foundation. etc. I hope magic leap team is aware of this problem and it would be solved in the future.

@brs_kes
I understand that downgrading your project is not an ideal solution, apologies for that!

But just to clarify, this issue is caused by changed made by the Unity Engine in version 6 and above. That’s why downgrading your project to a non Unity 6 version helped the resolve the issue.

Unfortunately this isn’t something that Magic Leap can solve alone since it’s a Unity Engine issue, not Magic Leap specifically.

Please let me know if you need any further assistance and best of luck to you with your project!

Best,
Corey

@cfeist thank you for returning. I hope this will be resolved in the future. The ironic thing is that outdated Hololens 2 has no problem with new versions. I hope Unity is aware of this issue. I’m looking to update my Unity version to the latest again. Maybe it will suddenly fixed at 6.4 version who knows..

1 Like