Windows Directory

So, question. Say I wanted to save in the (mydocuments/games/gamename/savedata)
How would I query the information from windows the rest of the path. Like, if the User name is Kevin, how do I know it is Kevin so I can do C:\USERS\Kevin\MyDocuments\Games\GameName\SaveData I can’t find a command in unity scripting reference or the .net libraries.

As a secondary quick question that isn’t that important because I am sure I can look it up later. Is there a users file that I should be saving to in MacOSX or just save to the directory of the game.

Thanks.

You should really use Application.persistentDataPath from the Unity library to determine where to save games.

If you really want to go to the My Documents folder…

For Windows: System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) will give you the path all the way to My Documents.

For Mac: You’ll want to get the Application Support folder, but it’s not so easy to make it cross platform. See this article: Finding or creating the application support directory

Again, don’t do those things unless you need to, like you’re reading data from another application. Just use Application.persistentDataPath.

Depending on what you need to read/write, perhaps even PlayerPrefs would do the job for you.

Good info there, squidbot!

It seems to me Application.persistentDataPath is poorly named, at least for OS X. This is because it resolves to /Users//Library/Caches//, but ~/Library/Caches is not meant as a persistent data store. Really, it should resolve to /Users//Library/Application Support/.

Users routinely, whether it’s advisable or not, use tools to clear their caches. All your saved game data would be wiped out.

I’m considering filing a bug/request to change the return value of persistentDataPath.

Thanks for all the info guys. Sometimes it is hard to find stuff in the microsoft help places unless you have a hint of what you are looking for. In this case I had no idea where to search, I did search though.