About Json format and Player Prefs

I’m making an Offline RPG game in Unity. I want to save some things in my game. I have heard of two recording systems for this, one is PlayerPrefs and the other is to save in json format. PlayerPrefs is simple and easy to hack, and it does not work on all devices in json format. I do not consider the json format because it cannot be played on every device, and since the game is offline, I do not see any harm in doing it with PlayerPrefs. What do you think, what would be better for me to do?

They are both equally easy to hack (as in: modify).

Json provides more flexibility and it works on all devices. You just cannot write to every location on every device, and for WebGL specifically additional file I/O restrictions exist.

Playerprefs don’t allow you to save collection types, only int, float, bool and string. It’s also increasingly cumbersome to use at scale because you need to have a unique key for every new item whereas json simply serializes from/to serializable C# classes directly.

In both cases you need to consider what needs to happen when you make changes to the save format after release. Loading an older save file must continue to function after every update, therefore you also need to implement at least a rudimentary versioning and switching the loading process based on the version of the saved data, providing default values for newly added variables and ignoring values that have been removed, and also redirecting values to renamed variables.

1 Like

Only one of these is an actual “system”: PlayerPrefs. JSON is a file format. You can combine them having all of your data stored as JSON in a single PlayerPrefs entry but you shouldn’t use PlayerPrefs for anything other than basic preferences (eg resolution, audio volume, input selections, etc) due to some platforms having very tight limits.

On Windows PlayerPrefs is stored within the Windows Registry which is only meant to have small amounts of data stored within it. I don’t know what the actual limits are these days but you can screw things up for a user if you try to use it excessively on that platform.

On WebGL there is an enforced limit of 1MB.

Since JSON is just a file format it can be used on every device. You just need a storage method that is compatible with that device. Some platforms have restrictions on what you’re allowed to do on them (eg WebGL can’t access the file system).

Everything stored on a user’s computer is trivial to hack. You don’t even need to have the file format. You can just modify memory directly via tools like Cheat Engine. It’s even doable on platforms like iOS which are supposed to be locked down.

1 Like

I understand Thank you for the valuable information you provided. When I combine the videos I watched online and what you said, I understand better what you mean.