- Home /
AssetBundles don't load to scene on Android device.
Open example projects as "CharacterCustomization" and "AssetBundles" and i tried all methods to load assetbundles into scene.
PURPOSE: loading files with resources - .unity3d (locally on Android the device)
Let's take for example the AssetBundles Tutorial project.
Scene: "Loader".
Compiled *.unity3d copied in the folder "./Assets/StreamingAssets/"
In the InstantiateResource.js file registered a way for version Android
if (Application.platform == RuntimePlatform.Android)
download = new WWW ("jar:file://" + Application.dataPath +"!/assets/" + url);
In the Unity editor works without mistakes. Build .apk version for Android. Run apk on the device (SGS 2). On GUI press the DOWNLOAD buttons. Then shows % ... 100% and UNLOAD. But in a scene anything isn't present!
I tried many ways. Tried to compile under Android4 started on the ICS device - too anything. Check files in APK of "assets" folder - .unity3d files presents.
Though the project works in PC/MAC/WebPlayer... And when project switched to Android - work. No works compiled APK on Android device (many devices used HTC, SonyErricsson).
Well. thought there can be a matter in JAVA. Opened the tutorial "CharacterCustomization" project. This project is written on C#. Also add code:
...
if (Application.platform == RuntimePlatform.Android)
...
... "jar:file://" + Application.dataPath +"!/assets/" ...
Just the same problems. Everywhere works except Android devices! On scene nothing, not create.
Maybe this is BUG on engine(Android)? Or how to build loading of assetbundles on android device?
ZIP of AssetBundle example: http://www.sendspace.com/file/uizyxh
Unity 3.5 Android 2.3.6 and 4 (both on Samsung Galaxy S II)
Answer by pesche · Apr 16, 2012 at 03:49 PM
I have exactly the same problem with Android and Asset Bundles. Therefore I hope anybody could give us some hints.
thanks
Hey pesche , di you get a solution fo rthis. Im trying to load asset bundle from sd card. I use www.LoadFromCacheOrdownload(path,version). The file exists , but when i check for bundle it says null:(
Answer by udaanparvaz · Jul 25, 2012 at 12:33 PM
This may be late to answer but i think the script that you are using to build .unity3d assetBundles is missing the BuildTarget.Android in BuildPipeline.BuildAssetBundle arguments
Hey udaan, di you get a solution fo rthis. Im trying to load asset bundle from sd card. I use www.LoadFromCacheOrdownload(path,version). The file exists , but when i check for bundle it says null. I actually do set the optional parametrer when i took a build for asset bundle
I've done this without any problems or whatsoever...use a script to make asset bundle and make sure the script contains BuildTarget.Android....and then load the assetBundle using WWW class...I would suggest to Use Application.Persistentdatapath for android....which usually points to mnt/sdcard/Android/data/your_package_name/files/ dir on Android
this is exactly what i have done, but i get a argument null reference when i access the bundle from another script.
Answer by shaystibelman · Nov 14, 2012 at 10:30 AM
Here are my scripts for saving an asset bundle from an entire scene and then loading it into another scene:
Save asset bundle:
import System.IO;
#pragma strict
#pragma downcast
@MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")
static function ExportResource () {
// Bring up save panel
var path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// Build the resource file from the active selection.
var selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
/*
BuildPipeline.BuildPlayer
BuildOptions.BuildAdditionalStreamedScenes
*/
Selection.objects = selection;
}
}
@MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")
static function ExportResourceNoTrack () {
// Bring up save panel
var path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
}
}
@MenuItem ("Build/ExportToWebplayer")
static function MyBuild4web(){
var lvlname : String = Application.dataPath+"/"+Path.GetFileName(EditorApplication.currentScene);
var level : String[] = [lvlname];
BuildPipeline.BuildStreamedSceneAssetBundle(level, "Assets/StreamingAssets/"+Path.GetFileNameWithoutExtension(EditorApplication.currentScene)+"pkg.unity3d", BuildTarget.WebPlayerStreamed);
}
@MenuItem ("Build/ExportToAndroid")
static function MyBuild4android(){
var lvlname : String = Application.dataPath+"/"+Path.GetFileName(EditorApplication.currentScene);
var level : String[] = [lvlname];
BuildPipeline.BuildStreamedSceneAssetBundle(level, "Assets/StreamingAssets/Android/"+Path.GetFileNameWithoutExtension(EditorApplication.currentScene)+"pkg.unity3d", BuildTarget.Android);
}
(This code is to be put in an EDITOR folder directly in your ASSETS folder!)
The code to import the asset bundle:
if (Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer){
download = new WWW.LoadFromCacheOrDownload ("../StreamingAssets/" + url,1);
}
yield download;
if (download.error != null)
{
Debug.Log(download.error);
return;
}else{
var asset : AssetBundle = download.assetBundle;
var async : AsyncOperation = Application.LoadLevelAdditiveAsync(StoreName);
}