Question by
Newaxekub · Jul 20, 2019 at 08:11 AM ·
androidassetbundledownload
Can't save and load AssetBundle on android device
Hello
I have problems with save and load AssetBundle files on android device. It can work on a PC without problems.
IEnumerator DownloadFile()
{
string fileName = "scenes";
using (UnityWebRequest uwr = UnityWebRequest.Get("https://www.wwwwwwwwwwww.com/" + fileName))
{
string m_Path = Path.Combine(Application.persistentDataPath, "Asset_Bundles");
m_Path = Path.Combine(m_Path, "data");
if (!Directory.Exists(m_Path))
{
Directory.CreateDirectory(m_Path);
}
uwr.SendWebRequest();
while (uwr.downloadProgress != 1.0)
{
process_txt.text = string.Format("{0:P1} : ", uwr.downloadProgress);
yield return null;
}
if (uwr.isNetworkError || uwr.isHttpError)
{
process_txt.text = "Error!!!";
}
else
{
m_Path = Path.Combine(m_Path, fileName);
System.IO.File.WriteAllBytes(m_Path, uwr.downloadHandler.data);
}
}
}
and this is load AssetBundle code
void Start()
{
string m_Path = Path.Combine(Application.persistentDataPath, "Asset_Bundles");
m_Path = Path.Combine(m_Path, "data");
m_Path = Path.Combine(m_Path, fileName);
LoadAssetBundle(m_Path);
}
void LoadAssetBundle (string url)
{
assetBundle = AssetBundle.LoadFromFile(url);
show_txt.text = assetBundle == null ? "Fail to load assetbundle" : "Assetbundle succesfully loaded";
var scene = assetBundle.LoadAsset(prefeb_name);
Instantiate(scene);
}
The file has already been loaded into the device but cannot load AssetBundle
This is an error, But on desktop it can work with not a problems, What's wrong with File.WriteAllBytes on android.
capture.png
(16.8 kB)
capture.png
(37.6 kB)
Comment
Best Answer
Answer by Newaxekub · Jul 20, 2019 at 08:44 AM
Now I have a solution.
It is my own fault to create AssetBundle.
I change
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows64);
To
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android);
Now it can work, Thank you.
Your answer
Follow this Question
Related Questions
Assetbundles in Unity 5.x 0 Answers
Android Downloads Folder 2 Answers
Build game with asset bundle marked assets 0 Answers
Assets Bundle size increases 20 times after download 0 Answers