Search Unity

Load Asset Bundles from google drive

Discussion in 'Editor & General Support' started by V-J, Sep 18, 2019.

  1. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    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+<DownloadAsset>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?

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4.  
    5. public class LoadAssetBundlesRemote2 : MonoBehaviour
    6. {
    7.     public string assetName;
    8.  
    9.     void Start()
    10.     {
    11.         StartCoroutine(DownloadAsset());
    12.     }
    13.  
    14.     IEnumerator DownloadAsset()
    15.     {
    16.         using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(" The correct private google drive url"))
    17.      
    18.         {
    19.             yield return uwr.SendWebRequest();
    20.  
    21.             if (uwr.isNetworkError || uwr.isHttpError)
    22.             {
    23.                 Debug.Log(uwr.error);
    24.             }
    25.             else
    26.             {
    27.                 // Get downloaded asset bundle
    28.                 AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
    29.                 var prefab = bundle.LoadAsset(assetName);
    30.                 Instantiate(prefab);
    31.             }
    32.         }
    33.     }
    34. }
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Make sure the URL is pointing to AssetBundle itself, not to web page.
     
  3. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    Thx for your answer! solved by generating a direct link.
     
  4. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    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+<DownloadAsset>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.
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    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.
     
  6. Nithinsvs

    Nithinsvs

    Joined:
    Sep 3, 2017
    Posts:
    29
    Hey...how to get that "Direct Link" ??
     
    yingkongshi07 likes this.
  7. DoraWard

    DoraWard

    Joined:
    Apr 22, 2020
    Posts:
    1
    Good one. Thanks for sharing a nice piece of info.
     
  8. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Download the file and check what url it was downloaded from.
     
    Joe-Censored likes this.
  9. malhardevasthali007

    malhardevasthali007

    Joined:
    Apr 28, 2019
    Posts:
    2
    can you please help me .. I am stuck
    even after generating direct link the same error
     
    neha_unity851 likes this.
  10. neha_unity851

    neha_unity851

    Joined:
    Oct 1, 2020
    Posts:
    1
    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 ..:) ..Pls try this ..
     
  11. gun_man

    gun_man

    Joined:
    Sep 19, 2020
    Posts:
    16
    Hi, Im just curious how to save the bundle from URL direct link instead download the bundle every time?
     
  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Asset bundle system has a caching system, read about it in our documentation.
     
    AshwinTheGammer and gun_man like this.
  13. gun_man

    gun_man

    Joined:
    Sep 19, 2020
    Posts:
    16
    Thanks mate.
     
  14. SteveP1999

    SteveP1999

    Joined:
    Jul 6, 2021
    Posts:
    1

    Attached Files:

  15. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732