I am developing an AR app for the iPhone in Unity which downloads asset bundles from a webserver and attaches them to image targets. So far almost everything is working--except that when the app tries to load the asset bundle, I get the following error:
'asset/bundle/url' can't be loaded because it was not built with the right version or build target.
I created the assetbundles using the following script, modified slightly from the Unity documentation:
using UnityEditor;
public class CreateAssetBundles
{
[MenuItem ("Assets/Build AssetBundles")]
static void BuildAllAssetBundles ()
{
BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.iOS);
}
}
I then uploaded the assetbundles to the server using scp. The app downloads the assetbundles fine but cannot load them. Here's the code:
IEnumerator DownloadAndCache (string username, string modelName){
// Wait for the Caching system to be ready
while (!Caching.ready) {
Debug.Log ("Waiting on caching");
yield return null;
}
//Compute request url for server
UriBuilder uriBuilder = new UriBuilder();
uriBuilder.Scheme = "http";
uriBuilder.Host = BaseURL;
uriBuilder.Path = username.Trim() + "/" + modelName.Trim();
string BundleURL = uriBuilder.ToString ();
Debug.Log ("Attempting to download " + BundleURL);
// 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, version)){
yield return www;
if (www.error != null) {
Debug.Log ("Download error");
throw new Exception ("WWW download had an error:" + www.error);
}
AssetBundle bundle = www.assetBundle;
Debug.Log ("Got assets "+string.Join(",", bundle.GetAllAssetNames ()));
GameObject loadedModel = Instantiate(bundle.LoadAllAssets()[0]) as GameObject;
//attach to the image target
loadedModel.transform.parent = ImageTargetTemplate.gameObject.transform;
loadedModel.transform.position = new Vector3 (0, 0, 0);
loadedModel.transform.localScale = new Vector3 (1, 1, 1);
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
So far I have tried:
- Setting the build target BuildTarget.iPhone - no difference
- Building the assetbundles using the assetbundle manager API from Unity
- Unchecking "strip engine code" in the build options for iOS - I heard on another forum that this can cause problems.
Any help appreciated.
-UPDATE-
I modified the BuildAssetBundle script per Programmer's suggestion and switched the target platform from "iPhone" to "Universal" in the player settings panel. I'm pretty sure this is what resolved the problem.