Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    2,597
    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:
    2,597
    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:
    11
    Hey...how to get that "Direct Link" ??
     
  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,087
    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
     
unityunity