reading downloaded and cached AssetBundle in a scene (Sprites, Animations, Sounds e.g.)

I’m using Asset Browser of Unity and built as Android. then i downloading as cache but I don’t know how to read it. I’m stuck here. I wanted to make like DLC you know.

this is downloader as cache (using AssetBundleManager at github):

public string bundleName = "BundleNameHere";
        public string url = "file:///Users/****Desktop/Unity Projects/***/AssetBundles/";
        private AssetBundleManager abm;

        private void Start()
        {
            abm = new AssetBundleManager();
            abm.SetBaseUri(url);
            abm.Initialize(OnAssetBundleManagerInitialized);
        }

        private void OnAssetBundleManagerInitialized(bool success)
        {
            if (success) {
                abm.GetBundle(bundleName, OnAssetBundleDownloaded);
            } else {
                Debug.LogError("Error initializing ABM.");
            }
        }

        private void OnAssetBundleDownloaded(AssetBundle bundle)
        {
            if (bundle != null) {
                // Do something with the bundle
                abm.UnloadBundle(bundle);
            }
            Debug.Log(Caching.defaultCache.path);
            abm.Dispose();
        }

this is getting AssetBundle (but giving error; “instantiate is null”):

public string url = "file:///Users/****/Library/Caches/Unity/***/****/97d6aeaead9461a2b739e4e9cac5f9ba/__data";

IEnumerator Start()
    {
        var uwr = UnityWebRequest.GetAssetBundle(url);
        yield return uwr.SendWebRequest();

        // Get the designated main asset and instantiate it.
        Instantiate(DownloadHandlerAssetBundle.GetContent(uwr).mainAsset);
    }

So I’m using this

public string url = "file:///Users/****/Library/Caches/Unity/***/****/97d6aeaead9461a2b739e4e9cac5f9ba/__data";
IEnumerator Start()
    {
        while (!Caching.ready)
            yield return null;

        using (var www = WWW.LoadFromCacheOrDownload(url, 5))
        {
            yield return www;
            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log(www.error);
                yield return null;
            }
            var myLoadedAssetBundle = www.assetBundle;

            var asset = myLoadedAssetBundle.mainAsset;
        }
    }

I don’t understand what is your problem?
Normally you would put asset bundles somewhere online and use UnityWebRequest.GetAssetBundle(url, …)
The methods with extra arguments besides URL will attempt load bundle from cache and will download. if bundle isn’t cached.

I get it but how to import and read the bundle at runtime? downloading and caching but not reading. I’m stucak at read the bundle. Also should i remove the folders that what i mean? sprites, animations, sounds will read from cache.

Also again, UnityWebRequestGetAssetBundle does not work. giving error; “instantiate is null”

This is because you don’t check for errors. Does UnityWebRequest succeed? Is returned AssetBundle not null?
According error, you pass null to Instantiate(), perhaps you didn’t provide main asset when building the bundle?

the error is this:

ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
UnityEngine.Object.Instantiate (UnityEngine.Object original) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:175)
LoadAssets+<Start>c__Iterator0.MoveNext () (at Assets/Scripts/LoadAssets.cs:35)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

URL path is this: public string url = file:///Users/****/Library/Caches/Unity/****/scenes/86d6b0bf4c733c01362a991aa82a2cae/__data

(***) this is private. I can’t show because of this

Is this on your desktop machine. You mentioned Android, did you build AssetBundles for Android?
Bundles built for Android can only be loaded on Android, but you URI not for Android.

ah yes you’re completely right I thought this actually. thanks for this. Well then How can i read this? this code works with reading? otherwise should i write another script?

So I built it for Android, this is OK. but if i remove builded folders(sprites,animations,scenes,sounds) from Assets folder, then will it give error at Runtime? otherwise this will read builded folder as directly?

You need to build asset bundles specifically for platform you want to load them on, meaning separate bundles for different platforms.
Normally you would put bundles on some server from where they can be downloaded. If you want to distribute them with application, then StreamingAssets folder is suitable place for bundles, you resolve it at runtime via Application.streamingAssetsPath

should i delete these folder? because the sprite gameobjects could not read the sources. I asked because of it. if i don’t delete, then the apk size will increase