Search Unity

Bug Application.persistentDataPath not behaving as expected on Mac

Discussion in 'Scripting' started by DuncanAbrakam, Jul 29, 2021.

  1. DuncanAbrakam

    DuncanAbrakam

    Joined:
    Jul 29, 2021
    Posts:
    8
    I am working on a problem happening only for Mac users. My unity version is 2020.3.5f1.

    From the documentation:
    I have many issues with it. First, let's note that the path described as ~/Library/Application Support/company name/product name is working almost fine. If I have data in it, the game launches by reading at this location. However, if I use th path ~/Library/Application Support/unity.company name.product name, I do not get to read anything and the game starts on a new file. Here start the strange things. According to the documentation, unity is still supposed to look at this location, it is just not supposed to use it as default in "Recent versions of unity". A message present in the documentation since Unity 5.5, that's old.

    But I get even stranger things to happen. If I start a new game (either when using the unity.application.product style path which is not detected, or simply by deleting everything), the new game will be stored in a folder called com.application.product, which is never metionned anywhere in the documentation.

    I will also add that logging the output from the editor and build give different results.

    Editor: ~/Library/Application Support/company name/product name
    Build: ~/Library/Application Support/com.company name.product name

    Does anybody have any kind of information about it ? I'm thinking about adding a special case for Mac users to hard code the path but I would definetly prefer to get a clean solution.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Editor and build don't use the same location. That isn't a bug, it's by design. It's true on PC as well.

    You should be using Application.persistentDataPath, and Unity will store stuff where it needs to. Are you trying to set the path yourself based on the reference?
     
    Bunny83 likes this.
  3. DuncanAbrakam

    DuncanAbrakam

    Joined:
    Jul 29, 2021
    Posts:
    8
    I have more informations now. Editor and Build use different locations - for this point I wasn't sure, but ok now I've the answer.

    The thing is that I do have these two path (both from the same build)
    ~/Library/Application Support/com.company name.product name
    ~/Library/Application Support/unity.company name.product name

    which get used on MacOS without any real information. Some people have files in the first and others in the second. The major problem is that the second one isn't referenced in the Unity Documentation anywhere, and I don't see any reason used by Unity to choose between them. Probably the only difference is the OS version. It's only on mac that a user gets "randomly" a result for the Application.persistentDataPath. This is being a problem to work with Steam cloud which requires one precise path for one OS.
     
  4. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    I have the same problem.
    Does anyone have any information on this problem?
    Nowhere in the documentation does it say that they are stored in paths starting with `com.`.
     
  5. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Checking in to point out that this is screwing half of my mac players from steam cloud too.
     
  6. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
  7. DuncanAbrakam

    DuncanAbrakam

    Joined:
    Jul 29, 2021
    Posts:
    8
    For information as I see other people have encountered this problem, we ended up hard coding the save location for mac users, and wrote a file migration script that runs when the game is launched before loading the saved files to ensure people who had the "wrong" path got their files moved.