On Demand Resources downloads data but can't access to it.
Hi everyone!
I'm having some problems converting my project from WWW to OnDemandResources requests for loading bundles. I was using Unity 5.5.4.p5 and I've tried Unity 2018.1 without success.
I've tried the demo assetbundlemanager (https://bitbucket.org/Unity-Technologies/assetbundledemo) but didn't work either (loads resources in xcode correctly and www server works, but it won't work in ODR mode in Testflight).
I tried using a CollectResources load like the example, and it correctly loads UnityData, but GetResourcePath returns null for every file I'm trying to retrieve. The resource names doesn't feature extensions here.
I've also tried to manually load the files into XCode, setup the OnDemand tags and retrieve files from inside there, without success too. This code is from this version.
The code will download the ondemandresources tag, fills up to 100% done without errors. Then trows and error because the odr:// doesn't exist.
This is the error:
Request result file: 01.bundle odr://01
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<LoadFromODR>c__Iterator1:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
ODR temp File: :
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<LoadFromODR>c__Iterator1:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
UnauthorizedAccessException: Access to the path "auto/" is denied.
Do you have any ideas about how to fix this?
This Debug.Log("ODR temp File: " + request.GetResourcePath(bundleResources[iFile].Replace(".bundle",""))); outputs no output file.
I can't use www anymore, and ondemandresources is my only alternative for this project, so I would like to know how to fix this issue.
Thanks everyone!
static IEnumerator LoadFromODR(string path, string odrTag, string[] bundleResources){
//waits for the other threads to finish
while(request != null){
yield return new WaitForSeconds(1);
}
//initializes request
Debug.Log("Start ODR for:" + odrTag);
request = OnDemandResources.PreloadAsync(new string[] { odrTag });
while (request.isDone == false)
{
Debug.Log("Request:" + odrTag + "-" + (request.progress * 100) + "%");
yield return new WaitForFixedUpdate();
}
if (!string.IsNullOrEmpty(request.error))
{
Debug.LogError("ERROR LOADING BUNDLE FROM ODR: " + request.error);
// ODRPrompts.instance.DoDebug("ERROR LOADING BUNDLE FROM ODR: " + request.error);
yield break;
}
Debug.Log("Start ODR resources request for:" + path + " - " + odrTag + " - " + string.Join(",",bundleResources));
// ODRPrompts.instance.DoDebug("Start ODR request for:" + path + " - " + string.Join(",", odrTag));
for (int iFile = 0; iFile < odrTag.Length; iFile++)
{
string fileName = bundleResources[iFile];
Debug.Log("Request result file: " + bundleResources[iFile] + " odr://" + bundleResources[iFile].Replace(".bundle", ""));
// ODRPrompts.instance.DoDebug("Request result file: " + odrTag[iFile] + " odr://" + odrTag[iFile]);
Debug.Log("ODR temp File: :" + request.GetResourcePath(bundleResources[iFile].Replace(".bundle","")));
Directory.CreateDirectory(path);
Debug.Log("Directory Created:" + path);
//copy request back to assets
try{
File.Copy("odr://" + bundleResources[iFile].Replace(".bundle", ""), Path.Combine(Application.persistentDataPath, path + fileName));
Debug.Log("Copied file WWW to persistent:" + Path.Combine(Application.persistentDataPath, path + fileName));
//bundle.mainAsset
//locks file (prevents iCloud backup)
Device.SetNoBackupFlag(Path.Combine(Application.persistentDataPath, path + fileName));
}catch(IOException ex){
Debug.Log("ERROR:" + ex.Message);
// ODRPrompts.instance.DoDebug("ERROR:" + ex.Message);
}
Debug.Log("Copied file ODR to persistent:" + Path.Combine(Application.persistentDataPath, path));
// ODRPrompts.instance.DoDebug("Copied file ODR to persistent:" + Path.Combine(Application.persistentDataPath, path));
}
request.Dispose();
request = null;
}
Your answer
Follow this Question
Related Questions
Texture Array 0 Answers
iOS - Placing Texture2Ds in Array cause Memory Leak? 0 Answers
Unity can not access StreamingAssets on IOS 1 Answer
Crash when load scene with mesh from assetbundle on iOS devices 0 Answers
Weird Issue: Textures become transparent when running from the editor in an android platform 0 Answers