Load Asset BundleScene from Save Location

Afternoon folks,

I have recently decided I needed to learn how to use Assetbundles and have been getting my share of bumps and bruises. However, it has been fun and there is a ton of documentation to help out someone who has no idea how they work. I have watched hours of tutorials and read the recent documentation for Webrequest and its benefits. The problem I am having is that I want to load the file from the location I saved the asset bundle to. Also, I chose the request and save method used because of the size of our bundles. I want to be able to download it, and load the scene on Click of a button(not auto). I also want to be able to delete or uninstall the assetbundle.

Maybe if I can get help figuring out how this whole thing works then I could figure out the rest.

Anyhow, thanks for the help in advance. The below script is my attempt at putting the things together I have learned over the past 5 days. Current issue is that I get an error

private AssetBundleCreateRequest bundleRequest;
    private UnityWebRequest request;
    private DownloadHandler downloadHandler;

    public string sceneURL;
    public string sceneName;
    private bool sceneDownloaded = false;
    private bool sceneDownloading = false;
    public Slider downloadBar;
    public static string dlcPath;


    public void PlatformSaveLocationCheck()
    {
        print("Detected Device Type" + Application.platform);

        if (Application.platform == RuntimePlatform.Android)
        {
            dlcPath = Application.persistentDataPath + "/DLC/";

            if (!Directory.Exists(dlcPath))
            {
                Debug.Log("Directory Created at" + dlcPath);
                Directory.CreateDirectory(dlcPath);
            }
        }
        else
        {
            dlcPath = Application.dataPath + "/DLC/";

            if (!Directory.Exists(dlcPath))
            {
                Debug.Log("Directory Created at" + dlcPath);
                Directory.CreateDirectory(dlcPath);
            }
        }
    }

    IEnumerator Start()
    {
        PlatformSaveLocationCheck();

        string path = Path.Combine(dlcPath, sceneName + ".unity3d");

        if (File.Exists(path))
        {
            StartCoroutine(LoadBundleScene());
            Debug.Log("Already Downloaded");   
        }
        else
        {
            //get the bundle
            var request = new UnityWebRequest(sceneURL, UnityWebRequest.kHttpVerbGET);


            request.downloadHandler = new DownloadHandlerFile(path);
            sceneDownloading = true;

            //set actual wait time for server communication
            yield return request.SendWebRequest();

            if (request.isNetworkError || request.isHttpError)
                Debug.LogError(request.error);
            else
                Debug.Log("File successfully downloaded and saved to " + path);
        }
    }

    IEnumerator LoadBundleScene()
    {
       
        bundleRequest = AssetBundle.LoadFromFileAsync(Path.Combine(dlcPath, sceneName));

        Debug.Log("Asset Already Downloaded. Loading Scene");

        if (bundleRequest == null)
        {
            Debug.Log("Failed to load AssetBundle!");
        }
        else
        {
            yield return null;

            if (bundleRequest.isDone)
            {
                Debug.Log("Found Asset Bundle");
     
                LoadScene();

            }
        }
    }


    public void LoadScene()
    {
        if (sceneDownloaded)
        {
            SceneManager.LoadScene(sceneName);
        }
        else
        {
            return;
        }
    }

    private void Update()
    {
        /*if (sceneDownloading)
        {
            if (request.downloadProgress > 0 && request.downloadProgress < 0.99f)
            {
                downloadBar.value = request.downloadProgress;
            }
        }*/
    }

Nevermind the downloadbar portion at the bottom. I need to figure out how to use that since I switched from WWW which was working fine to Webrequest so I don’t know where to call it where it doesnt automatically equal 1

From error it looks your sceneName variable is simply empty, also the path you save bundle to and the path you load from is different, because you append “.unity3d” to the former.
Also, why aren’t you using DownloadHandlerAssetBundle ?

I was getting an error about assetbundles not being able to access raw data. I was using something like request.downloadhandler.data but I will look into it again.

So, basically I have to pull the scenename without extension from the assetbundle?

I may be mistaken but doesn’t my start() save it to the DLC folder?

I assigned the .unity3d after someone else told me that I would have issues fetching the data without using that extension

You can’t access raw data in DownloadHandlerAssetBundle, not in DownloadHandlerFile, these are specifically designed to not keep large amount of data in memory.
Why do you need raw data anyway? DownloadHandlerAssetBundle automatically loads the asset bundle for you and you can get already loaded AB out from it.