PlayerPrefs or save file?

Many forum posts recommend using PlayerPrefs to save a player’s progress or other data, and I’ve used that in the past; but it prevents the player from making a backup of their game or transferring their saved games to other machines. So is it better to save the data to a file somewhere in the game’s directory? If so, the file needs to be safe from being overwritten if the game files are patched with a new version. What are the “best practices” for this, or what do players expect?

Preventing users from patching? If that means cheating then you can encrypt the data other wise dont even bother if its a singleplayer game. If it doesnt hurt other people why does it matter if they ruin their gameplay experience?

Users usually expect their game data to be either where they installed it or in the documents folder or the app data folder. Usually in another folder named by the game name or company.

Best practices? Saving json or xml data directly into a text file and loading it.

Good luck on it.

2 Likes

By “safe from patching” I meant keeping the file from being overwritten if the game files are patched with a new version. I’ll edit my post to make it clearer.

Generally it’s recommended to new developers for the sake of simplicity but the real purpose of it is just to store settings.

Best practices are platform dependent.

1 Like

Good point what if Unity added a cloud storage option for player prefs, would that negate the problem or create more issues (e.g. Gamer Logins/Passwords)?

Or how hard would it be to set up cloud storage for your Unity game?

For Windows, PlayerPrefs uses the registry to store its data. Why Unity chose to do this when it appears that every other operating system or device gets saved to a file I do not know. But it means that if you have any intention of selling to the Windows market, you should absolutely not use PlayerPrefs.

On my PC, I expect a game to store settings and saves under AppData. I’m used to having to poke around between Local, LocalLow, and Roaming because the game studios and software developers can’t agree on which one to use.

i.e.: C:\Users[NAME]\AppData\Local\Crashlands

I will accept putting it under Documents, though that’s mostly because a number of companies do it whether you want them to or not and so I’ve become used to it.

i.e.: C:\Users[NAME]\Documents\ANNO 2070

I full-out DESPISE when a piece of software uses the registry. I cannot easily back up or change the settings or saves. This leads to registry bloating and can lead to registry corruption. Plus, there have been issues with various versions of Windows where frequent registry access can create garbage files or have other side effects.

There was an early access game created with Unity that had large, complicated saves. (Think open world exploration with lots of data.) I had been looking to buy the game until I found out they were using PlayerPrefs to save all of the data. That was an instant, “No way in hell,” for me. I did later buy the game, but not until the developers added a real save system to the game.

3 Likes

Another service for them to manage? Its not a bad idea though could gain profits for them but I honestly would rather keep Unity working on Unity.

Its really not that difficult to set up cloud storage, you can do it through php and www requests or C# through ASP.NET. There are a ton of tutorials on creating these.

That confirms some of my own misgivings about using PlayerPrefs. Is there any reason not to just save stuff in the game’s own folder, though? I’m trying to figure out what I’m missing here.

Actually, no, there’s no big reason not to have a Saves folder in the install directory and/or put preferences in there. There are plenty of programs that do it.

About the only reason I can think of is that if you have saves, screenshots, and settings in a directory other than the game’s itself, when you uninstall the game you can leave those saves and such in place without leaving a lingering folder under C:\Program Files\whatever.

So PlayerPrefs is only needed for mobile devices that don’t allow saving normal files?

Mobile devices allow you to write files. eg. iOS has a few locations that an app can use for writing data. You can get a path from Unity using https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

For what it’s worth, I’ve just switched from a very complex (I make RPGs), semi-customised PlayerPrefs, to the Easy Save asset from the store.

Can’t recommend it enough.

1 Like

There are almost no programs that do it. It’s 2018 over here, most developers have realized already that in normal usage under unprivileged (non-administrative) account application simply does not have access for writing in “Program Files”. So the usual practice is to write to user home subdirectory.

1 Like

Actually, it was February 4, 2017, when I wrote the post, so nice bit of thread necromancy just to try and pick a fight. :face_with_spiral_eyes:

3 Likes

I made a free tool to help with this sort of thing: GitHub - richardelms/FileBasedPlayerPrefs: Unity lib for json file based PlayerPrefs.