- Home /
The question is answered, right answer was accepted
Where to put save file ?
I have a game that can be installed by a .exe. The save file is created in the same folder than the other files of the game. The issue is that, if the game is installed in a protected folder like Program Files, the save file can not be created or used because of restricted access. I think to create the save file in the AppData folder, but I don't know if it's a good way to solve my problem as this folder has not the purpose to contain save files. Is there a way to overcome the restriction of the Program Files folder ? If not, where would be the best place to put save files ?
$$anonymous$$eep the save files in a folder with the game files and make it a hidden folder.
"as this folder has not the purpose to contain save files" What do you mean by this? If you refer to Application.persistentDataPath, then it's a perfectly good place to keep the save files. Some people would argue that it takes too much space on the system drive, but that just depends on the number of files and their sizes.
For me the AppData folder should be used only for app config files. But I suppose it's fine to put save files in.
The great advantage of persistentDataPath is that it's always going to exist and be writable.
Given the OP's focus on "AppData" perhaps they're only deploying to Windows, in which case there'd be some sense in allowing people to save elsewhere (easier to navigate to, easier to back up, avoid filling up a small system drive, etc). But that's not going to be possible on many other platforms, and you need a default. The simplest default is going to be persistentDataPath for the reasons stated in first para, but some Windows users would probably thank you for defaulting to %USER%/Documents or something like that, ins$$anonymous$$d.
I support @jedBeryll oppinion, I use the persistent datapath on andoid (where application datapath cant be accessed normally) and app Datapath on portable editions, if you use a installer on windows Program Files, persistentDatapath is a good idea:
//save two files, one after completely close the other, so if first fails, second with previous game can be recovered by the user, (or with the open file code)
static string RecordsPath = Application.persistentDataPath + "/Records.jg";
static string RecordsPath2 = Application.persistentDataPath + "/~Records.jg";
//to debug, put editor saves inside proyect folder
#if UNITY_EDITOR
RecordsPath = Application.dataPath + "/../Records.jg";
RecordsPath2 = Application.dataPath + "/../~Records.jg";
#endif
Answer by Firox_ · Aug 29, 2019 at 04:40 PM
Thank you for your responses. I will use the AppData folder to put my save file.