Search Unity

The asset bundle can't be loaded

Discussion in 'Editor & General Support' started by epic1989, Apr 11, 2014.

  1. epic1989

    epic1989

    Joined:
    Apr 6, 2014
    Posts:
    5
    Hi,

    I'm new in unity, so i'd like to ask about this problem

    I built an asset bundle for my vuforia project to include the scene and scripts and animations .. using this code

    Code (csharp):
    1.  
    2. using UnityEditor;
    3. using UnityEngine;
    4. using System.IO;
    5.  
    6. public class AssetBundleBuilder {
    7.    
    8.     [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
    9.     static void ExportScene(){
    10.         string pathSceneFileName = EditorUtility.OpenFilePanel("Build Scene", "Assets", "unity");
    11.         Debug.Log(pathSceneFileName);
    12.         if (pathSceneFileName.Length == 0) {
    13.             EditorUtility.DisplayDialog("AssetBundleBuilder", "Choice Scene File", "OK");
    14.             return;
    15.         }
    16.         string sceneFileName = Path.GetFileNameWithoutExtension(pathSceneFileName);
    17.         Debug.Log(sceneFileName);
    18.         string assetBundleFileName = EditorUtility.SaveFilePanel("Save AssetBundle", "", sceneFileName, "unity3d");
    19.         if (assetBundleFileName.Length == 0) {
    20.             EditorUtility.DisplayDialog("AssetBundleBuilder", "Input AssetBundle File Name", "OK");
    21.             return;
    22.         }
    23.         string[] levels = new string[] {pathSceneFileName};
    24.         string errorMessage = BuildPipeline.BuildStreamedSceneAssetBundle(levels, assetBundleFileName, BuildTarget.iPhone);
    25.         if (errorMessage.Length == 0) {
    26.             EditorUtility.DisplayDialog("AssetBundleBuilder", "Build Success!", "OK");
    27.         } else {
    28.             EditorUtility.DisplayDialog("AssetBundleBuilder", errorMessage, "OK");
    29.         }
    30.     }
    31. }
    32.  
    After generating the unity3d file i uploaded it to my server using Filezilla (FTP application) .. and then i created new unity project to download the asset bundle and load it .. and then i built this project to "iPhone" Device

    This this my download code:
    Code (csharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class AssetBundleSample : MonoBehaviour {
    7.    
    8.     //public GUIText guitext;
    9.     public string guitext;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         // Clear Cache
    14.         Caching.CleanCache();
    15.        
    16.         string loadUrl = "http://epic-demo.com/unity/igate.unity3d";
    17.        
    18.         StartCoroutine(load(loadUrl, 1));
    19.     }
    20.    
    21.     // Update is called once per frame
    22.     void Update () {
    23.         // progress
    24.         int percent = (int)(www.progress * 100);
    25.         //guitext.text = percent.ToString() + "%";
    26.         guitext = percent.ToString() + "%";
    27.         //Debug.Log(guitext);
    28.     }
    29.    
    30.     private WWW www;
    31.    
    32.     private IEnumerator load(string url, int version) {
    33.         // wait for the caching system to be ready
    34.         while (!Caching.ready)
    35.             yield return null;
    36.        
    37.         // load AssetBundle file from Cache if it exists with the same version or download and store it in the cache
    38.         www = WWW.LoadFromCacheOrDownload(url, version);
    39.         yield return www;
    40.  
    41.         Debug.Log("Loaded ");
    42.        
    43.         if (www.error != null)
    44.             throw new Exception("WWW download had an error: " + www.error);
    45.  
    46.  
    47.         AssetBundle assetBundle = www.assetBundle;
    48.         //Instantiate(assetBundle.mainAsset);
    49.         string leveName = "lAGAT";
    50.         Application.LoadLevel (leveName);
    51.  
    52.         // Unload the AssetBundles compressed contents to conserve memory
    53.         //assetBundle.Unload(false);
    54.     }
    55.  
    56.     void OnGUI()
    57.        
    58.     {
    59.         GUI.Label( new Rect( 40, 40, 120, 50 ), "Progress: " + guitext );
    60.        
    61.     }
    62. }
    63.  
    When running the application on editor it working, but if run it on my iPhone device the scene doesn't appear and i get this message in console

    "The asset bundle 'http://epic-demo.com/unity/igate.unity3d' can't be loaded because it was not built with the right version or build target. Level 'lAGAT' (-1) couldn't be loaded because it has not been added to the build settings.
    To add a level to the build settings use the menu File->Build Settings…"

    Can anybody help me?
     
  2. epic1989

    epic1989

    Joined:
    Apr 6, 2014
    Posts:
    5
    Hey,
    Any answer?!!!!!!!!
     
  3. epic1989

    epic1989

    Joined:
    Apr 6, 2014
    Posts:
    5
    Thanks to god .. i solved the problem
    Just replace "BuildTarget.iPhone" with "EditorUserBuildSettings.activeBuildTarget"

    "EditorUserBuildSettings.activeBuildTarget" will build on any platform target
     
  4. puspa93

    puspa93

    Joined:
    Jun 13, 2014
    Posts:
    1
    Hi epic1989
    I'm a newbe in unity and vuforia, can you tell me step by step about it?
    thank you :)