Search Unity

[SOLVED] Crashing App: Download asset bundle for use in AR on Android

Discussion in 'Asset Bundles' started by jipsen, Feb 17, 2020.

  1. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    37
    I hope someone can help. Sorry if this is obvious but I have been trying to download my asset for days to use in Augmented Reality, with no luck.

    I created a bundle with:
    Code (CSharp):
    1. [MenuItem("Assets/Build AssetBundles")]
    2.     static void BuildAllAssetBundles()
    3.     {
    4.         BuildPipeline.BuildAssetBundles(@"F:\MyPath", BuildAssetBundleOptions.None, BuildTarget.Android);
    5.     }
    I uploaded all the generated files onto my web server using Binary upload.

    Then, in my scene, I download the bundle using:

    Code (CSharp):
    1.  
    2. public string assetName;
    3. private GameObject asset;
    4.  
    5. IEnumerator Start()
    6.     {
    7.         using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("https://MyPath/argirl"))
    8.  
    9.         {
    10.             yield return uwr.SendWebRequest();
    11.  
    12.             if (uwr.isNetworkError || uwr.isHttpError)
    13.             {
    14.                 Debug.Log(uwr.error);
    15.             }
    16.             else
    17.             {
    18.                 // Get downloaded asset bundle
    19.                 AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
    20.                 asset = bundle.LoadAsset<GameObject>(assetName);
    21.                 //Instantiate(asset);
    22.             }
    23.         }
    24.        
    25.         /*string url = "https://MyPath/argirl";
    26.         UnityEngine.Networking.UnityWebRequest request
    27.             = UnityEngine.Networking.UnityWebRequestAssetBundle.GetAssetBundle(url, 0);
    28.         yield return request.SendWebRequest();
    29.         AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
    30.         asset = bundle.LoadAsset<GameObject>(assetName);
    31.         //Instantiate(asset);*/
    32.     }
    The commented out code above is another way I tried. Both work fine in Unity during run time using Instantiate(asset), but when I build it to my Android phone, it loads the asset bundle and then crashes the app when I try to place the "asset" GameObject in augmented reality later on.

    I've read a lot on forums about different things to use but I'm new to asset bundles and don't know how to fix this. Also, I'm working with Unity 2019.3.0f6. Any help is appreciated!!!
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Have you checked whether the bundle or asset are not null. They can be, if load fails, for example.
     
  3. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    37
    No, it isn't null. It loads the asset fine when I test it in unity, like I said.
     
    Last edited: Feb 18, 2020
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    You have to check it on device as well. Also note, that asset bundles have to be built for the platform you're loading them on, Editor bundles are not compatible with Android etc.
    Finally, have you looked into logcat? It might contain something that helps to pinpoint the reason.
     
  5. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    37
    Isn't this building a bundle for Android??
    BuildPipeline.BuildAssetBundles(@"F:\MyPath", BuildAssetBundleOptions.None, BuildTarget.Android);
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Yes, it is, but make sure you actually load that file and not something else.
    Other than that, only logcat can provide a clue, why it fails.
     
  7. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    37
    OK... turns out that it was something SUPER obvious. lol I needed to add .prefix to my asset nameName. Glad to know my code above was correct though!
     
  8. Irina-uk

    Irina-uk

    Joined:
    Feb 14, 2014
    Posts:
    62
    Please tell me how you solved this problem?
     
  9. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    37
    Umm... like I said, I added the .prefix to my asset name when calling it.