I’m experiencing an issue with On-Demand Resources (ODR) in my Unity iOS project. Despite setting up everything correctly and verifying that asset bundles are being downloaded, I’m facing a peculiar problem where the download completes, but the loading process fails, and the error message provided is empty.
Here’s a brief overview of my setup and the problem:
Unity Version: 2022.3.10f1
Xcode Version: 15.2
iOS Version on Device: 17.4.1
Asset Bundle Setup: Asset bundles are tagged and built specifically for iOS.
Issue Description:
When I initiate an ODR request to download asset bundles, the request completes, and the assets appear to be downloaded (as indicated by Xcode’s console logs). However, an error occurs right after, with the Unity log showing "ODR request failed: :: ", but no error message is displayed. Here is the snippet from my Unity code where I handle the download and error:
private void LoadAssetBundleFromOnDemandResources(string assetBundleName, string lobbyPrefabName)
{
UnloadCurrentAssets();
Debug.Log($"PAD/ODR :: Loading prefab {lobbyPrefabName} from AssetBundle :: {assetBundleName}");
string[] tags = new string[] { assetBundleName };
var request = OnDemandResources.PreloadAsync(tags);
StartCoroutine(DisplayDownloadProgressIOS(request));
request.completed += (asyncOperation) =>
{
if (asyncOperation.isDone)
{
if (request.error != null)
{
Debug.LogError($"ODR request failed: {request.error} :: {request.error.ToString()}");
}
/////
rest of code
/////
}
};
}
Console Output:
Here is the console output captured when the issue occurs:
Xcode Log:
Checked the integrity and compatibility of the asset bundles.
Ensured paths used in Unity match those logged in Xcode.
Added detailed logging around the asset loading process.
Despite these steps, the issue persists without any clear error message. It appears that the completion handler is being called correctly, but there is a disconnect in loading the asset bundle from the provided path.
Has anyone faced a similar issue, or does anyone have insights or suggestions on what might be going wrong here? Any help or pointers would be greatly appreciated as I’ve been stuck on this for a while.
Yeah , I tried that. “request.error” return a empty string for some reason. It should be null when asset is downloaded properly.
Main problem is that :
the path returned is also a empty string. Due to this nothing can be loaded
Code :
private void LoadAssetBundleFromOnDemandResources(string assetBundleName, string lobbyPrefabName)
{
UnloadCurrentAssets();
Debug.Log($"PAD/ODR :: Loading prefab {lobbyPrefabName} from AssetBundle :: {assetBundleName}");
string[] tags = new string[] { assetBundleName };
var request = OnDemandResources.PreloadAsync(tags);
StartCoroutine(DisplayDownloadProgressIOS(request));
// _request = request;
request.completed += (asyncOperation) =>
{
if (asyncOperation.isDone)
{
if (request.error != null)
{
Debug.LogError($"ODR request failed: {request.error} :: {request.error.ToString()}");
}
string path = request.GetResourcePath(assetBundleName);
Debug.Log($"Checking path before loading: {path}");
if (File.Exists(path))
{
_loadedAssetBundle = AssetBundle.LoadFromFile(path);
Debug.Log($"Loaded AssetBundle from path: {path}");
if (_loadedAssetBundle != null)
{
_lobbyPrefab = Instantiate(_loadedAssetBundle.LoadAsset<GameObject>(lobbyPrefabName), transform);
_lobbyPrefabName = lobbyPrefabName;
}
else
{
Debug.LogError($"PAD/ODR :: Failed to load AssetBundle {assetBundleName}. AssetBundle is null.");
}
}
else
{
Debug.LogError($"AssetBundle file does not exist at path: {path}");
}
}
else
{
Debug.LogError($"PAD/ODR :: Failed to preload On-Demand Resources for {assetBundleName}. Error: {request.error} :: {request.error.ToString()}");
}
};
}
Console Log :
Checking path before loading:
<>c__DisplayClass15_0:<LoadAssetBundleFromOnDemandResources>b__0(AsyncOperation)
UnityEngine.AsyncOperation:InvokeCompletionEvent()
AssetBundle file does not exist at path:
UnityEngine.AsyncOperation:InvokeCompletionEvent()
Accessing resources failed with error: Error Domain=NSCocoaErrorDomain Code=4099 "Connection invalidated to streaming unzip service." UserInfo={NSLocalizedDescription=Connection invalidated to streaming unzip service.}
The file has problem in getting unziping or is it something else? Is there is restriction on what assets can be packed in asset bundle for on-demand resources?
I cleared the Xcode derived data , and the issue of unzip-ing went away.
but while running debug on Xcode , i found these observation:
disk gauge shows that asset packs are present and shows their status.(image below)
when prompted to download, the files get downloaded. verified on device settings (app’s data&documents increases by asset pack size)
the path returned is still null, so asset bundle does not load on the game.
on stopping the game, the app’s data&documents decreases to original size(suggesting that the asset pack never got saved) . Maybe thats why there is no path of asset packs when prompted.
I don’t know how to fix this. Any help appreciated
use this , after the request was completed ,and the asset loaded. You guys should mention to use this “res://” while loading asset bundle through on-demand resources in the tutorial. And if you can explain why is this required.