Load Asset Bundles from google drive

Hi,
I’m developing for the Oculus Quest (Android) I followed with succes this online youtube tutorial about using assetbundles using Unity 2018

In this tutorial it stores the bundles locally, in my case i want to download the assetbundle from google drive and instantiate the gameobject in the scene.

So i changed my code but when pressing play in the editor i get the following errors;

  1. Error while downloading Asset Bundle: Failed to decompress data for the AssetBundle
  2. NullReferenceException: Object reference not set to an instance of an object LoadAssetBundlesRemote2+d__2.MoveNext () (at Assets/Scripts/LoadAssetBundlesRemote2.cs:29)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

Here is what my code looks like. What do i need to change to get it working?

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class LoadAssetBundlesRemote2 : MonoBehaviour
{
    public string assetName;

    void Start()
    {
        StartCoroutine(DownloadAsset());
    }

    IEnumerator DownloadAsset()
    {
        using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(" The correct private google drive url"))
     
        {
            yield return uwr.SendWebRequest();

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
            }
            else
            {
                // Get downloaded asset bundle
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
                var prefab = bundle.LoadAsset(assetName);
                Instantiate(prefab);
            }
        }
    }
}

Make sure the URL is pointing to AssetBundle itself, not to web page.

Thx for your answer! solved by generating a direct link.

I get 2 errors: Callstack are below
Error while downloading Asset Bundle: Failed to decompress data for the AssetBundle ‘https://drive.google.com/file/d/1Q6iJtulozr0kBeUaR01ONn-CUizMtDHH/view?usp=sharing’.

NullReferenceException: Object reference not set to an instance of an object
AssetManager+d__2.MoveNext () (at Assets/Scripts/AssetManager.cs:63)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <092936fdc0c1418db54a09908cfb1cd1>:0)

share link: https://drive.google.com/file/d/1Q6iJtulozr0kBeUaR01ONn-CUizMtDHH/view?usp=sharing

I get errors at line 16 and 28.
28 is understandable since the asset bundle itself was not downloaded. What am I doing wrong with the link? It’s a direct link to the manifest file.

This is not the correct URL to your asset bundle. This link gives me a Web Page that has a download button.
What you need is a direct link, meaning when you paste URL to browsers address bar, you should get a file download immediately, not a web page loaded.

Hey…how to get that “Direct Link” ??

1 Like

Good one. Thanks for sharing a nice piece of info.

Download the file and check what url it was downloaded from.

1 Like

can you please help me … I am stuck
even after generating direct link the same error

1 Like

malhardevasthali007 i resolved the problem by creating direct link of file and then convert the share settings by restricted to anyone on the internet …by right clicking>share on the file in google drive …:slight_smile: …Pls try this …

Hi, Im just curious how to save the bundle from URL direct link instead download the bundle every time?

Asset bundle system has a caching system, read about it in our documentation.

2 Likes

Thanks mate.

Hello guys! I have the same problem, i have generated the direct link:
https://drive.google.com/uc?export=download&id=1_aDUe_QZNuX6ZXnExTvUjiTtV6V1MLY3
But it still would not let me load the bundle. The code i use:

When I click the link, it still opens me a web page, most likely UnityWebRequest also gets that page.
Using browser dev tools I extracted this link, which seems to give a file:
https://drive.google.com/uc?export=download&id=1_aDUe_QZNuX6ZXnExTvUjiTtV6V1MLY3&confirm=t&uuid=fe8bc44a-731d-4597-9eb2-5bc15bf93fa4