- Home /
Android wont load AssetBundle scene - using AssetBundleManager from the tutorial (Unity 5.2.1)
Hello dear Unity Community.
I'm fairly new to Unity and I'm trying to learn how to use AssetBundles in Unity as I will need them for the next app. I found this AssetBundle tutorial and decided to use the AssetBundleManager included in the downloadable sample project. In the 'Build Settings' I switched to Android Platform. I build the AssetBundles (for Android platform). I want to load a scene from the AssetBundle. When I'm in the editor I used three different ways to load the AssetBundle scene. First I tried it in 'Simulation Mode ', then the 'Local AssetBundle Server' and finally I uploaded the AssetBundle to a server and accessed it through the url. Everything worked perfectly in the editor.
When I try it on my Android devices it won't download from the URL.
I use the scene and AssetBundle given in the tutorial project. The AssetBundle is named 'scene-bundle'. Let's say I upload it to this site: http://www.MyWebsite.com/AssetBundles/ then the AssetBundle file url would be this: http://www.MyWebsite.com/AssetBundles/Android/scene-bundle
In the editor it worked when I gave this url: http://www.MyWebsite.com/AssetBundles/ because the script detects which platform I'm in and the name of the AssetBundle is given in a string beforehand.
the Script-line reads like this:
AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");
In the comment above it says this:
Customize the URL based on your deployment or configuration
So my guess is, that I just can't write the url like that and need to adapt it to Android?
The error I get is the following:
Failed downloading bundle scene-bundle from http://www.MyWebsite.com/AssetBundles/Android/scene-bundle: Invalid Unity Web File (Decompression Failure). URL: http://www.MyWebsite.com/AssetBundles/Android/scene-bundle
I tried to use WWW because I thought that might help, but I failed miserably.
All the answers I found were a couple of years old and nobody is using the unity AssetBundleManager. The tutorial is also fairly recent, Date: 11 Sep 2015.
Any help would be greatly appreciated. I'm sorry for being such a noob, thank you for your time.
Did you create separate bundles for your editor as well as for android? From what I see, I think you are trying to use the same bundle("scene-bundle") for every platform.
Thank you for your time, but as I stated above I build the AssetBundles for Android platform. They also work in the editor if Android is selected as platform in the Build Settings.
$$anonymous$$y problem is I don't know how to load assets or scenes using the AssetBundle$$anonymous$$anager. I just managed to load assets without the $$anonymous$$anager using the code posted here. That works on my Android devices. Scenes have proven to be more difficult, I haven't accomplished it yet.
IEnumerator DownloadBundleAndCache (string BundleURL){
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using(www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
//DOWNLOADING...
yield return www;
//DOWNLOADING CO$$anonymous$$PLETE
if (www.error != null){
Debug.LogError("WWW download had an error:" + www.error);
}
else{
_instance.bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else{
string path = "assets/resources/images/myImage.png"; //How I load my Sprite. Load other resources similarly.
Sprite sprite = bundle.LoadAsset<Sprite>(path);
}
bundle.Unload(false);
}
}
}
Something what I use. See if it helps.
@Digzou, can you provide a link, please, to the doc where it says that LoadLevelAsync is Pro-only? I would think that if Unity 5 has enabled AssetBundle functionality in the personal edition, then the features/functions included in the tutorial would be valid for all versions. If not, well, that'd be a little messed up.
@ZeFirestarter , I saw your post in the tutorial thread as well, and as I said over there, I've been having a similar issue . . . did you ever get this resolved?
Thanks in advance to you both!
@ZeFirestarter, that's what I was asking you! I thought maybe since your issue was older that you may have figured it out by now. I just posted in the tutorial thread yesterday. :-)
In any case, @twobob has pointed out that this (my issue, at least, maybe yours as well) is due to a $$anonymous$$I$$anonymous$$E type / server config problem, which I'm in the middle of resolving . . . will post progress in the tutorial thread.
cheers
Answer by ZeFirestarter · Feb 01, 2016 at 12:35 PM
So now I'm working with Unity 5.3.1 with the same Tutorial/AssetPackage and it worked on the first try on Android. It loads the asset example, the scene and the variants examples. All work on Android and none of them work on iOS :-/. I made the AssetBundle with iOS selected as platform (while using Windows) and uploaded that AssetBundle. I'll try again later creating and uploading the assBundle from the Mac.
What also gave me problems was a compression error, that was because I was uploading the AssetBundles with Filezilla. Go to "Options -> Transfer -> Data Type -> un-check the first box with the ASCII-data (you can leave the one with 'dotfiles' checked) (I have the German version that's why I don't know exactly what it says in English).
If anyone has questions how to get the AssetBundleManager to work on Android, let me know. Write here or PM me, I'll be sure to help as much as I can. Cheers.
Dude, this is exactly the problem I was having, cheers!
Hello @ZeFirestarter! Could you help me to build an Asset Bundle for Android?
Do you think there will be too many differences for a pc build? should be simpler, right? Can I pm you if this is the case
hi @ZeFirestarter i am facing same issue in andriod ,while running application in editor its works fine where it does not work in andriod device ,how to overcome this using asset bundle manager please let me know as soon as possible
Thank you in advance, vignesh
Answer by RanjithSoman · Apr 02, 2017 at 09:55 AM
I am using unity3d 5.5.2f1 and vuforia 6.2 sdk. I have built asset bundles for android and uploaded it to my [server][1]. I am using vuforia to detect markers and then attach the asset bundle to the marker. The script works well in the editor. However after building it and running on the android, it doesn't work. I checked whether its problem with vuforia by attaching another game object to the target. That one appears while on editor and on phone. However only gameobject is getting attached after building on to android and not the assetbundle.
using System;
using UnityEngine;
using System.Collections;
using Vuforia;
public class Loadmyasset : MonoBehaviour, ITrackableEventHandler
{
public string AssetName;
public int Version;
private GameObject mBundleInstance = null;
private TrackableBehaviour mTrackableBehaviour;
private bool mAttached = false;
public string BundleURL;
void Start()
{
StartCoroutine(DownloadAndCache());
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
IEnumerator DownloadAndCache ()
{
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
BundleURL = "http://rksunityftpserver.x10host.com/assetbundle/Android/tree.unity3d";
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using (WWW www = WWW.LoadFromCacheOrDownload (BundleURL, 1))
{
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else
Instantiate(bundle.LoadAsset(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
public void OnTrackableStateChanged (TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED || newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
if (!mAttached && mBundleInstance) {
// if bundle has been loaded, let's attach it to this trackable
mBundleInstance.transform.parent = this.transform;
mBundleInstance.transform.localScale = new Vector3 (10.0f, 10.0f, 10.0f);
mBundleInstance.transform.localPosition = new Vector3 (0.0f, 0.15f, 0.0f);
mBundleInstance.transform.gameObject.SetActive (true);
mAttached = true;
}
}
}
}
Please help me on this issue [1]: http://rksunityftpserver.x10host.com/assetbundle/Android/