- Home /
Application Support / LocalApplicationData
I would like to have access to a persistent folder to write cache data to in my cross platform (Mac/Windows) Unity app.
My impression is that on Macs the correct folder should be
~/Library/Application Support/
and on Windows it would be something like
%USERPROFILE%\Local Settings\Application Data\
Now, it seems like there is almost a way to get this cleanly because on Windows I believe the following function returns the right location.
System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
Unfortunately for whatever reason it doesn't appear to return the corresponding location on Macs. So my solution was to #ifdef by platform and use this one
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
which for me resolves to the root of user directory (~/) and then I add the necessary subdirs onto it.
The trouble is that when I started testing my app on other Macs it ended up returning the ~/Documents directory for other users.
Is there a recommended and cleaner way to deal with all of this?
I have the same problem, and haven't yet found a better solution. Here's a forum thread which arrives at the same conclusion as well: http://forum.unity3d.com/threads/23686-SOLVED-Special-folder-path-in-mac Wish you the best of luck in finding a more elegant solution!
Answer by Nicolaj Schweitz · Dec 27, 2010 at 05:17 PM
Please refer to the current* Mono documentation on this issue:
http://www.go-mono.com/docs/index.aspx?link=T:System.Environment%2bSpecialFolder
*The code is not maintained by Unity Technologies and may change without our knowledge.
Thanks - but on my $$anonymous$$acbook Pro running snow leopard, SpecialFolder.ApplicationData, SpecialFolder.LocalApplicationData, and SpecialFolder.Personal (the best options on the page you linked) return /Users/Ad$$anonymous$$/.Config, /Users/Ad$$anonymous$$/.local/share, and /Users/Ad$$anonymous$$/Documents, respectively. I guess there is no elegant way to achieve this.
Yes, appreciate the attempt but it's not really an answer to my question. I'm not quite sure what you are implying with this answer -- don't use those functions because we have no control over mono? Or, here is what mono does with that, use it with that in $$anonymous$$d? If there isn't a consistent clean cross-platform way to get this folder then it would be nice if Unity provided something directly.
Answer by Andres Martinez · Sep 06, 2011 at 11:46 PM
If you select the API Compatibility Level as "Net 2.0" (not the Subset option), the path in a Mac is correctly identified as the user folder and not the Documents folder.