- Home /
 
Automatically load asset bundles on start from cache
Uploaded an assetBundle to a server, in my scene i have a download button that downloads the asset and caches (saves) them in the iphone documents folder, and instantiates the required object using:
 var request = assetBundle.LoadAsync("Sphere", typeof(GameObject));
 
 Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity);
 
               upon closing the app and reopening it i want the downloaded asset to load automatically on start, i have a script that checks if the file exists it instantiates it according to the following code
 IEnumerator Start () {
          print ("START FIRST");
         
     
          strPath = GetiPhoneDocumentsPath ();
         
          cachedAssetBundle = strPath + "/savedassetbundle.assetbundle";
         
         Debug.Log(cachedAssetBundle);
         
         if(File.Exists(cachedAssetBundle)) 
         {
             started=true;
         
         download = new WWW(cachedAssetBundle);
         yield return download;
             
             AssetBundle assetBundle = download.assetBundle;
             
 
         AssetBundleRequest request = assetBundle.LoadAsync("Sphere", typeof(GameObject));
         yield return request;
         
         Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity);
         
         download.assetBundle.Unload(true);
         }
     }
 
               Notes: 1) i am testing on an iPhone
2) the check for if an asset bundle exists works, as i have a game object that rotates when i close and reopen the app after downloading if started = true;
The problem is when i close and reopen the application the asset bundle doesnt load automatically on start, even though the asset bundle exists
how do you deter$$anonymous$$e that it is not loaded? If it is just because it is not shown on the screen, I suspect the problem could be due to the Unload(true)
i deter$$anonymous$$ed that its not loaded because it's not shown on the screen i commented the line containing Unload(true), still it didn't show up All i want to do is display the object on screen on start
i get the following errors
You are trying to load data from a www stream which had the following error when downloading. malformed UnityEngine.WWW:get_assetBundle() c__Iterator1:$$anonymous$$oveNext() (at Assets/Example Project/Plugins/Show.cs:72)
all right, then it "could" be that you did not build the assetbundle for iOS. The BuildPipeline.BuildAssetBundle has a targetPlatform parameter and it must be set to iPhone
Your answer
 
             Follow this Question
Related Questions
Audio: how do I immediately play a new audioclip without delay(code included)? 2 Answers
GetComponent Help. 1 Answer
How to access Vuforia C# library from Javascript 2 Answers
C# try catch block doesn't work for iOS? 2 Answers
Multiplayer Problems 1 Answer