Search Unity

Application.persistentDataPath inconsistency

Discussion in 'Editor & General Support' started by dotsquid, Aug 2, 2021.

  1. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    On Steam our game has 2 versions: a payed full one and a free demo one.
    When the player buys the full version it copies the progress from the demo and continues from where the player stopped in the demo. It is implemented pretty simple. To store the progress we use '<Application.persistentDataPath>/Demo' for the demo version and '<Application.persistentDataPath>/Full' for the full version. So it's quite easy to copy required files from one folder into another one.
    However, it appeared that this feature neither works on Mac OSX after we updated the project to one of the latest versions of Unity (2019.4.21).
    The thing is that for the demo version Application.persistentDataPath is 'Library/Application Support/<Company Name>/<Product Name>', but for the full version it is 'Library/Application Support/<Application Identifier>'. Obviously, it's kinda impossible to rely on these paths anymore.

    Any clues why Unity chooses different paths?

    PS. Both versions are implemented as a single project. We just update product name and some preprocessor directives during the build.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Looks like this is a backwards compat thing. At some point in the past (before Unity 5.2), macOS persistent data path was stored in 'Library/Application Support/<Company Name>/<Product Name>'. However, in Unity 5.2 we changed it to be stored at 'Library/Application Support/<Application Identifier>' because that became a requirement for Mac App Store submission. However, to preserve backwards compatibility for older projects that were upgraded to 5.2, we first check if 'Library/Application Support/<Company Name>/<Product Name>' folder exists, and if it does, we use that (so that games could still find their old data). If it doesn't exist, we will use 'Library/Application Support/<Application Identifier>' instead.
     
  3. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    @Tautvydas-Zilys thanks for a quick reply.
    But it's kinda contradicts the documentation, no?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Interesting. Let me follow up on that!
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    It looks like the documentation is incorrect (it's swapped). Unity uses "~/Library/Application Support/unity.company name.product name" on macOS Standalone player. It was changed to that from "~/Library/Application Support/company name/product name" in 2011 (10 years ago!).
     
    cosformula likes this.