Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

Discussion in 'Asset Bundles' started by antifuzz, Oct 2, 2019.

  1. antifuzz

    antifuzz

    Joined:
    Feb 22, 2013
    Posts:
    99
    [[ 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.
     
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    @Aurimas-Cernius might know better than I do. iOS specific Bundle Identifier details are vague and fuzzy to me.
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,642
    Absolute paths are the subject to change indeed, but the data should be preserved and paths relative to Application.persistentDataPath should be present.
     
  4. antifuzz

    antifuzz

    Joined:
    Feb 22, 2013
    Posts:
    99
    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.
     
  5. DirtyFred

    DirtyFred

    Joined:
    May 17, 2014
    Posts:
    27
    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
     
  6. fahimmv29

    fahimmv29

    Joined:
    Apr 1, 2018
    Posts:
    1
    Code (CSharp):
    1. if (Directory.Exists(Application.persistentDataPath))
    2.         {
    3.             string worldsFolder = Application.persistentDataPath;
    4.             DirectoryInfo d = new DirectoryInfo(worldsFolder);
    5.             foreach (var file in d.GetFiles("*.unity3d"))
    6.             {
    7.                 if (file.Name == bundleName + ".unity3d")
    8.                 {
    9.                     path = file.FullName;
    10.                 }
    11.             }
    12.         }


    your path will be Changed. Hope this will help.....
     
    melvinwebros likes this.
  7. melvinwebros

    melvinwebros

    Joined:
    Jan 5, 2021
    Posts:
    1
    thank you ,it solved the issue