Search Unity

Application.persistentDataPath changing run-to-run on OSX?

Discussion in 'Scripting' started by Stephen-Lavelle, Jan 28, 2016.

  1. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    I've run the same game several times and sometimes i get

    persistentDataPath = /Users/stephenlavelle/Library/Application Support/increpare games/Sausage

    and sometimes i get

    persistentDataPath = /Users/stephenlavelle/Library/Application Support/unity.increpare games.Sausage

    Anyone have any idea what's going on? I'm trying to get steam cloud saving working, and, I don't know what's right! aah! is it that unity checks for fallback directories first, or? I'm super confused!

    There's no documentation on where persistentDataPath is on various platforms. I'm trying to get my game working with steam auto cloud sharing (where you can give it a path that it'll sync, vs using steam plugins), but if I can't provide a single stable path on OSX, then I can't use it and will have to have a dedicated steam build with the steamworks plugin dll.

    edit: to clarify, this is all happening in standalone builds.
     
    Last edited: Feb 1, 2016
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Try
    Code (CSharp):
    1. Appliction.dataPath
    Instead and see if that helps.
    I know personally dataPath works for me. (Im on Windows so it depends.)
     
  3. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    It's not correct to write to the datapath on OSX (and also in principle on windows, because the user may not have write permission to that directory);
     
  4. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    Ok, going to abandon persistentDataPath and just going to hardcode those paths.
     
  5. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    A friend told me this is still a problem. Lol. Here's my production-tested "reliable PersistentDataPath" code in the end in case anyone else stumbles across this:

    Code (CSharp):
    1.  
    2.     public static string PersistentDataPath =
    3.         #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
    4.         System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData),@"..\LocalLow\COMPANYGAME\APPNAME")
    5.         //"%USERPROFILE%/AppData/LocalLow/COMPANYGAME/APPNAME"
    6.         #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
    7.         homePath+"/Library/Application Support/unity.COMPANYGAME/APPNAME"
    8.         #elif UNITY_STANDALONE_LINUX
    9.         homePath+"/.config/COMPANYGAME/APPNAME"
    10.         #else
    11.         Application.persistentDataPath
    12.         #endif
    13.         ;
    14.  
    Don't forget to sub in your own company/app names there :) ( Or use Application.productName / Application.companyName )
     
    Last edited: Jun 6, 2019
  6. brettj

    brettj

    Joined:
    Feb 9, 2015
    Posts:
    43
    This still happens. I made a build using 2019.3.7 and on one Mac it's "~/Library/Application Support/company name/product name" and on another Mac it's "~/Library/Application Support/unity.company name.product name".

    If I delete the folders on each Mac, they are recreated in the same way, still different from each other. What is causing this? One thought is the one using the old format "unity.company name.product name" is an older computer that likely had an older version of Unity installed on it at some point and maybe there's some settings file somewhere reading that? No matter, this needs to be fixed.