Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kent_Engel · Feb 16, 2020 at 10:29 PM · androidassetbundledownloadquestsave file

Downloading Asset Bundle on Android and Saving to File

Just a little bit of background on this issue: I am trying to download an asset bundle from a server on android (Oculus Quest to be specific) and save that asset bundle as an OBB to the respective OBB folder for the application. Key piece of information: This asset bundle contains a bunch of 360 videos, and it seems that video is the only piece of media that Android has difficulties unpacking from a bundle.

Approaches that have not been successful:

I have tried the approach of using UnityWebRequest.Get() with a download handler to get the data, and then File.WriteAllBytes() to save the data and AssetBundle.LoadFromFile() to load the bundle. This works beautifully on PC in the editor, but causes the application to crash on the Quest due to what seem to be memory issues.

Trying a different approach, I used UnityWebRequestAssetBundle.GetAssetBundle() with a version identifier for caching, which again worked beautifully on PC in the editor, but could not load the videos on the Quest. This seems to be related to an issue with videos being loaded from the cache on Android rather than from a save location on the disk.

This led me to combine the two approaches based on research I did online to use UnityWebRequestAssetBundle.GetAssetBundle() to download the asset bundle, and AssetBundle.LoadFromFile() pointing to the folder that the bundle was cached in. Unsurprisingly, this returned the same error as before relating to the bundle / videos being cached rather than saved to storage.

This brings me to my question: Is there actually a way to download an asset bundle containing video files, save them to storage on Android (preferably in the OBB folder), and load the videos for playback in an app?

Below is a small sample of what I have been working with:

 loadingScreen.SetActive(true);
         webRequest = UnityWebRequestAssetBundle.GetAssetBundle(downloadURL, 1, 0);
         webRequest.SendWebRequest();
 
         while (webRequest.downloadProgress < 1.0f)
         {
             loadingSlider.value = webRequest.downloadProgress;
             yield return null;
         }
 
         if (webRequest.isNetworkError || webRequest.isHttpError)
         {
             Debug.Log($"Error thrown while communicating with server: {webRequest.error}");
         }
         else
         {
             Debug.Log("Download successful, hiding UI and playing next clip");
 
             loadingScreen.SetActive(false);
 
             if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
             {
                 myLoadedAssetBundle = DownloadHandlerAssetBundle.GetContent(webRequest);
             }
             else if (Application.platform == RuntimePlatform.Android)
             {
                 myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.persistentDataPath, androidBundleFileName));
             }
 
             PlayNextClip();
         }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andresleonardogomez · Sep 30, 2020 at 07:50 PM

Hola, mira soy muy nuevo en la programación de juegos, pero seguro te puedo ayudar: Si programas que hayan comportamientos diferentes al trabajar en Windows o Android, seguramente puede ocurrir que te funcione en uno y no en el otro. Por ello te recomiendo no hacerlo. Mira, tomé tu código y le hice unos pequeños arreglos para poder usarlo, a la función solo debes llamarla con la URL de descarga como la variable WWW y el nombre del prefabricado como Name. Haciendo eso, seguro te funcionará.

 using System.Collections;
 using UnityEngine.Networking;
 using System;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 
 // https://drive.google.com/uc?id=XXXXAquíVaElIdentificadorXXXXX&export=download&authuser=0
 
 public class DescargarMaterialNecesario : MonoBehaviour
 {
     public string BundleURL;
     public string NombreDelMódulo;
 
     public Slider loadingSlider;
     public GameObject loadingScreen;
 
     public Text MensajeTexto;
 
     public GameObject PrefatAsset;
     public AssetBundle BundleAsset;
     public AssetBundleRequest request;
 
 
     private UnityWebRequest webRequest;
     private void Start()
     {
         loadingScreen.SetActive(false);
     }

     public void DescargarEscenas( )
     {
         BundleURL = "https://drive.google.com/uc?export=download&id=1iomecdt9VG0KvDc_qeS_GepHcqe8oV5j";
         NombreDelMódulo = "F_Obj Sistema de Biblioteca";
         StartCoroutine(DownloadAndCache(BundleURL, NombreDelMódulo));
 
     }
 
     public IEnumerator DownloadAndCache(String WWW, String Name) {
         // Activamos la pestaña de carga
         loadingScreen.SetActive(true);
         /*Hacemos la solicitud, enviamos la página URL guardada 
         como "WWW", la versión que es la "1" y la entrada de sistem32 "0"*/
         webRequest = UnityWebRequestAssetBundle.GetAssetBundle(WWW, 1, 0);
         //Solicitamos que nos envíen el asset
         webRequest.SendWebRequest();
 
         //Mientras se descarga el Asset, miramos el avance en nuestra LoadingSlider
         while (webRequest.downloadProgress <= 0.99f)
         {
             loadingSlider.value = webRequest.downloadProgress;
             yield return null;
         }
 
         //Notificamos si hubo algún error, y si no lo hubo, pasamos adelante
         if (webRequest.isNetworkError || webRequest.isHttpError)
         {
             MensajeTexto.text = "Error al descargarlo";
         }
         // Si ni tenemos error alguno, escribimos que ya lo tenemos listo
         else
         {   //Mandamos mensaje al usuario diciendo que ya lo tenemos
             MensajeTexto.text = "Ya lo tenemos descargado!!!";
             
             
             //Identificamos si estamos en Windows o Android
             if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
             {
                 //Cargamos el Asset
                 BundleAsset = DownloadHandlerAssetBundle.GetContent(webRequest);
                 MensajeTexto.text = "Compilando para Windows";
             }
             if (Application.platform == RuntimePlatform.Android)
             {
                 //Cargamos el Asset
                 BundleAsset = DownloadHandlerAssetBundle.GetContent(webRequest);
                 MensajeTexto.text = "Compilando para Android";
 
             }
 
             // Convertimos nuestro asset Bundle en una request
             request = BundleAsset.LoadAssetAsync<GameObject>(Name);
             // Convertimos nuestra request en un prefat
             PrefatAsset = request.asset as GameObject;
             // Instanciamos el prefat
             Instantiate(PrefatAsset);
 
             //Desactivamos la pantalla de carga
             loadingScreen.SetActive(false);
 
         }
     }
 
 }
 

Lo único que debes hacer, es llamar la función, ponerle tu link y el nombre de tu asset. Un abrazo

Kent_Engel

Espero que a alguien más le pueda servir... me tomó muchos días tener el código.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

263 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android: Additional data download 0 Answers

What should I do with AssetBundle manifest ? 0 Answers

How to use AssetBundle on Android for external download 0 Answers

Android AssetBundle hangs on 100% download 1 Answer

Unity 5 Resources.LoadAsync on Android slower than iOS? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges