I cant seem to find where the external directory is with unity. I have tired
file://sdcard/file.ext
file:///sdcard/file.ext
file:///mnt/sdcard/file.ext
and everything in between.
I am trying to load my asset bundles with this code
AssetBundle bundle = AssetBundle.CreateFromFile(“file:///sdcard/animals.unity3d”); but it keeps saying
Failed to open file at path: file:///sdcard/animals.unity3d or whichever string i use for the file. I am getting really frustrated with this,and I cannot find any answers here that actually work.
I have found the answer. I was trying to open with Create from file but if you use www.LoadfromCachOrDownload(“file://sdcard/filename.ext”) it will load it up without any delay.
Although I am not sure if it will work on all android devices so if anyone has a better way please post it.
void Start() {
StartCoroutine(DownloadAndCache());
}
// Update is called once per frame
IEnumerator DownloadAndCache() {
while(!Caching.ready)
yield return null;
// example URL of file on PC filesystem (Windows)
// string bundleURL = "file:///D:/Unity/AssetBundles/MyAssetBundle.unity3d";
// example URL of file on Android device SD-card
string bundleURL = "file:///mnt/sdcard/AndroidCube.unity3d";
using (WWW www = WWW .LoadFromCacheOrDownload(bundleURL, Version)) {
yield return www;
if (www .error != null)
throw new UnityException("WWW Download had an error: " + www .error);
// Load and retrieve the AssetBundle
AssetBundle bundle = www .assetBundle;
Ten do whatever you want do with that assets. Imp: make sure in Manifest permission for ReadExternalSDcard is there