I can’t load an assetbundle from the /Documents folder of my app on IOS.
I tried all the answers i can found on internet but it still not working.
My script for Android, Windows, Mac OS X works but not on IOS.
I work on IOS 5.1 and later.
here is my script
i set the UIFileSharingEnabled of the Plist.info to true.
I use this part of the script in a coroutine launch in the Start()
Yes i’m sure that the file is placed at correct location, i used the file.Exist test to check this.
I tried whit the prefix “file://” but whit it, i have an error, the file doesn’t exist
Maybe it’s the problem ? the file without the prefix exist but with it, it doesn’t exist, that’s normal ?
I try the find on internet if there is an access problem, maybe i’m not autorhized to access /Documents, maybe i have to activate an option like
UIFileSharingEnabled ?
i will try to load a picture instead of an assetbundle
I just saw that i have an “/” in “Cube/Cube.assetbundle” maybe i have to use an “\” ? but my WWW find the file and the file.exist
i will try it maybe it’s just that
Then maybe file is found, but the platform of Asset Bundle does not match platform you are deploying on. When exporting Asset Bundle have you specified iPhone as target platform?
i though the problem come from my script so i create a new project with only on script just to test if i can open an assetbundle
the main script
using UnityEngine;
using System.Collections;
using System.IO;
public class script_testLoadIOS : MonoBehaviour {
// Use this for initialization
IEnumerator Start ()
{
if(File.Exists(@Application.persistentDataPath + "/test.assetbundle"))
{
WWW test = new WWW(@Application.persistentDataPath + "/test.assetbundle");
yield return test;
AssetBundle testA = new AssetBundle();
testA = test.assetBundle;
Instantiate(testA.Load("Cube",typeof(GameObject)),Vector3.zero,Quaternion.identity);
testA.Unload(true);
}
}
}
and here the script i use to create an assetbundle (it’s the code from unity scripting reference web site)
using UnityEngine;
using UnityEditor;
using System.Collections;
public class editor : Editor {
[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "assetbundle");
if (path.Length != 0) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.iPhone);
Selection.objects = selection;
}
}
}
i build then i run the app on Xcode with an ipad 5.1 simulator, it creates the documents folder then i paste the test.assetbundle in the /Documents folder of the simulator.
But again i have an error in Xcode,
Failed to load asset bundle
UnityEngine.WWW:get_assetBundle()
c__Iterator0:MoveNext()
First of all, As Mantas puida said, if you try to access a local file with the www class, you must prefix the path with “file://”.
Second for asset bundle you should use www.LoadFromCacheOrDownload to enable caching.
And Finally asset bundles have the extension .unity3d not .assetbundle
As i said in a reply, if i use “file://” in the path, my file don’t exist for unity, i think the problem comes from here,
i don’t think the extension of the file is necessary .unity3d, i use .assetbundle for my android and windows app ad it works.
i will try the LoadFromCacheOrDownload but my files are on the /Documents of my app on my ipad so it’s mean i have to cache my folder before i load it. I find that weird but i will try it.
The path you try to use is not correct, on no platform actually, assuming we talk about content you added in XCode or Unity for inclusion in the project, as the path you have there points to the folder where the application is in / the assets folder in the editor.
In none of these places, asset bundles can be (in the editor they could but you will get problems if you try to have them in the Assets folder directly)
For in editor it would likely want to go to the StreamingAssets folder.
For Android its quite a bit more complex (the documentation and Unity Answers have the path though)
For iOS you would need to go to the /Raw/ folder if it was StreamingAssets in Unity. If you have them in documents then you downloaded them before or copied them there without it being needed as you can access StreamingAssets directly. If you downloaded it from the web, you would best use LoadFromCacheOrDownload directly with the http address of the asset bundle though.
On iOS the WWW to load them from the streaming assets folder directly would look like
WWW test = new WWW("file://"+Application.persistentDataPath + "/Raw/test.assetbundle");
or in a full code:
void Awake ()
{
StartCoroutine(LoadBundle());
}
IEnumerator LoadBundle () {
WWW test = new WWW("file://"+Application.persistentDataPath + "/Raw/test.assetbundle");
yield return test;
// do something with test
test.Dispose ();
}
When you talk about the /Raw folder, you talk about the /Raw folder contain in the app ? (“file://” + application.datapath +“/Data/Raw”)
Because “file://”+Application.persistentDataPath + “/Raw/test.assetbundle” point to /Documents/Raw/test.assetbundle not the in app /Raw folder