03 - Protecting saved data (PlayerPrefs)
Goal: You will learn how to stop players from editing your save data, such as PlayerPrefs stored in the Windows registry or on their device.
The problem
Unity stores PlayerPrefs in a place the player can open:
- Windows: the registry
- Android and iOS: a preferences file in the app data
The names and values are plain text. A cheater opens the Registry Editor, double-clicks player.score, and types a new number.

Image 1: The Windows registry. A plain player.score value is easy to read and easy to change.
That hurts your game. Progress, coins, and unlocks that should be earned are one edit away.

Image 2: A save game with a cheated score of 300 / 300 stars. That progress was never earned in normal play.
The solution
Replace Unity's PlayerPrefs with Anti-Cheat ProtectedPlayerPrefs. It can hide the name of a save entry, encrypt its value, and notice when someone edited it by hand. To encrypt means to scramble the value so it cannot be read without a key.
This works in the Free and the Pro version.
Step 1: Switch to ProtectedPlayerPrefs
ProtectedPlayerPrefs is a drop-in replacement. The save location and the method names stay the same. In most cases you only change the class name.
Before:
PlayerPrefs.SetInt("player.score", 10);
int score = PlayerPrefs.GetInt("player.score");
After:
using GUPS.AntiCheat.Protected.Storage.Prefs;
ProtectedPlayerPrefs.SetInt("player.score", 10);
int score = ProtectedPlayerPrefs.GetInt("player.score");
It also supports more data types than Unity's PlayerPrefs. The full list is on the Protected PlayerPrefs page.
Step 2: Set up the protection
Open Edit > Project Settings > GuardingPearSoftware > AntiCheat. Go to the Global tab and find PlayerPrefs - Settings.

Image 3: The PlayerPrefs settings in the Anti-Cheat project settings.
- Hash Key (on by default): Stores the name of the entry as a hash, not as readable text. A hash is a short code made from the name. A cheater can no longer search for
player.score. - Value Encryption Key (empty by default): The secret used to encrypt the value. While it is empty, the value is not encrypted. If you change the key later, old saves can no longer be read.
- Allow Read Any Owner (on by default): Turn it off, and a save can be read only on the device that wrote it. That stops a player from copying someone else's save.
- Verify Integrity (on by default): Stores a signature next to the value. If a player edits the save by hand, the signature no longer matches.
Important
Set a Value Encryption Key before you ship. The shipped settings leave it empty, so values stay readable until you do.
Step 3: Handle a changed save
Protected PlayerPrefs do not report to a detector. When a save fails a check, the Get call throws an exception. That happens when:
- the save was edited and Verify Integrity is on, or
- the save comes from another device and Allow Read Any Owner is off.
Catch the exception where you load your save, and decide what to do:
int score;
try
{
score = ProtectedPlayerPrefs.GetInt("player.score");
}
catch (Exception)
{
// The save was changed or copied. Reset it, or flag the player.
score = 0;
}
Step 4: Pick another way to store (optional)
ProtectedPlayerPrefs is enough for most games. There are two more ways to work with protected saves.
A file you choose (ProtectedFileBasedPlayerPrefs). It has the same methods, but stores the data in a file. Set ProtectedFileBasedPlayerPrefs.FilePath to change where. The default is a file in Application.persistentDataPath.
Values in the Inspector (ProtectedIntPref, ProtectedFloatPref, ...). You set the name of the entry and a default value in the Inspector. In code you read and write through the Value property.
using GUPS.AntiCheat.Protected.Storage.Prefs;
using UnityEngine;
public class PlayerScore : MonoBehaviour
{
// Set the key ("player.score") and a default value in the Inspector.
public ProtectedIntPref score;
public void AddScore(int amount)
{
score.Value += amount;
}
}
There are matching types for bool, string, Vector2, Vector3, Vector4, and Quaternion.
The result
With Hash Key on and a Value Encryption Key set, the same save looks very different.

Image 4: The same registry after protection. The name is a hash and the value is encrypted.
The readable name is gone, and the value is an encrypted string. A cheater cannot tell which entry holds the score. If they guess and edit it, the save fails its check.
Settings reference: Protected PlayerPrefs.
Important: never store secrets
Warning
Protection makes cheating harder, but anything stored on the player's device can be read in the end. Never store real secrets in PlayerPrefs, protected or not. That includes server API keys, passwords, and unlock codes.
Next steps
- Protecting memory against Cheat Engine helps if cheaters edit live values in memory, not the save.
- Reacting to detected cheating and Punishing cheaters show what to do when a cheat is found.
Next guide: 04 - Protecting against speedhacks (Pro).
Back to the Guides overview.