AssetBundles not found after updating app. persistentDataPath is changing..?

[[ I posted this on the iOS forum the other day, but have had no response so trying again here in case anyone has any insight ]]…

I have an iOS app that downloads asset bundles from a server and uses some textures within them.

Everything works fine until I install an updated version of the app over the top of an old one (into which some assetbundles have already been downloaded).

At this point, all previously downloaded assetbundles can no longer be found, and xcode gives me the error:
Unable to open archive file: /var/mobile/Containers/Data/Application/50C3C8C7-B5F7-474C-A139-2588B4744520/Documents/myAssetBundle

I think the problem seems to be that Application.persistentDataPath appears to change when I install a new version of the app.

According to the docs:
"When you build the Unity application, a GUID is generated that is based on the Bundle Identifier. This GUID is part of persistentDataPath. If you keep the same Bundle Identifier in future versions, the application keeps accessing the same location on every update.

However, I can see that the value for GUID changes with each new version of the app that I build.
For example, here’s the paths from two subsequent versions of the app:
/var/mobile/Containers/Data/Application/3C08E206-135B-4606-89C0-165C2F71FEA3/Documents/myAssetBundle
/var/mobile/Containers/Data/Application/3521FC70-CE8C-4C9F-98B3-7227591CB876/Documents/myAssetBundle

I did find this old post on the same subject where a respondent claims that although the path DOES change between versions, any data download there should still be present at the new path. But is this true?? And if that’s the case, then why can’t I find my AssetBundles in it after updating the app?

The same project with same code works correctly on Android across updates. I did wonder whether it was something to do with the way xcode builds an app, so I’ve tried uploading two versions to the iOS App Store and installing them via Testflight, and the same issue is observed. Everything fine on the first install, but it can’t find the assetbundles after the update.

@Aurimas-Cernius might know better than I do. iOS specific Bundle Identifier details are vague and fuzzy to me.

Absolute paths are the subject to change indeed, but the data should be preserved and paths relative to Application.persistentDataPath should be present.

This is not what I’m observing in this project. The AssetBundles don’t seem to be present after the app updates. And yes, I’m looking for them in a path relative to Application.persistentDataPath and not using an absolute path.

Since my original post, I’ve worked around the problem by using the AssetBundle caching system as described here: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html

However, that’s a bit messy as it still means I’m having to handle existing users who’ve already got bundles downloaded that now can’t be found, but at least this method seems more robust between future app updates.

Hi,

I have the same problem. I am saving a .dat file, which contains the path to the images saved.
When i install a new version, or the same version again(i am not even uninstalling the previous one) the .dat is found, but the images are lost…

Did you guys find a solution?

Thank you

if (Directory.Exists(Application.persistentDataPath))
        {
            string worldsFolder = Application.persistentDataPath;
            DirectoryInfo d = new DirectoryInfo(worldsFolder);
            foreach (var file in d.GetFiles("*.unity3d"))
            {
                if (file.Name == bundleName + ".unity3d")
                {
                    path = file.FullName;
                }
            }
        }

your path will be Changed. Hope this will help…

1 Like

thank you ,it solved the issue