- Home /
AssetBundles are not working outside editor on PC or Android.
So, im just playing around with AssetBundles to store sound packs outside of the original .apk to reduce file size. I seem to have the system worked out, as it runs exactly how I would like while running in editor, unfortunately attempting the same processes outside of editor is failing and I'm not sure why...
Here is the snippet of code for the actual downloading of the file. What I'm trying to do is download the AssetBundle, then extract a base .xml of the files inside and save that elsewhere.
//work in editor
public IEnumerator DownloadBundle()
{
if(!Directory.Exists(Application.persistentDataPath + "/Bundles"))
Directory.CreateDirectory(Application.persistentDataPath + "/Bundles");
WWW www = new WWW(url);
yield return www;
//save to assetbundle to disk
SaveBytesAsFile(downloadPath, www.bytes);
//load in asset from disk
currentBundle = AssetBundle.CreateFromFile(Application.persistentDataPath + "/Bundles/AssetBundle.unity3d");
yield return currentBundle;
if(!Directory.Exists(Application.persistentDataPath + "/BundleData"))
Directory.CreateDirectory(Application.persistentDataPath + "/BundleData");
TextAsset a = currentBundle.Load("Bytes", typeof(Object)) as TextAsset;
File.WriteAllBytes(Application.persistentDataPath + "/BundleData/Bytes.xml", a.bytes);
}
Yeah, ignore the terrible formatting...
Any help on this would be greatly appreciated :)
Answer by Paulius-Liekis · Jan 25, 2015 at 10:56 PM
What's the platform of your asset bundles? My guess is PC (i.e. Standalone). AssetBundles are platform specific and you must build separate AssetBundles for each platform.
They are being saved as Android as the target platform, and as an uncompressed asset bundle.
What kind of indication is there that it doesn't work? What do you see in the log?
Uh.. What Log?
As for an indication, further on in the process it fails to load any of the data from the .xml like it had in previous iterations of the project.
Browsing the data path I'm using it does seem to download and extract the .xml from the assetbundle, but fails to read it. I mean this could be an issue in my read code, but I cant for the life of me figure out why it would be, as I haven't changed anything in that.
On PC (Standalone build): there should be a log after a run somewhere is the folder of your build.
On Android: use "abd log" command in a Ter$$anonymous$$al to see output from Debug.Log.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Loading Xml file issues 0 Answers
Save and Load data from Local XML file won't work 1 Answer
Baffled by Android storage system... 0 Answers