Dragonfly

Question: Where are PlayerPrefs stored in Unity?

Answer

PlayerPrefs is a class in Unity that is used for storing and accessing player preferences between game sessions. Here's where PlayerPrefs data is typically stored on different platforms:

Registry Example:
HKEY_CURRENT_USER\Software\MyCompany\MyGame
File Example:
~/Library/Preferences/com.mycompany.mygame.plist
File Example:
~/.config/unity3d/MyCompany/MyGame/prefs

Please note that while accessing or modifying PlayerPrefs is straightforward through the PlayerPrefs class methods like SetInt, GetInt, SetString, GetString, HasKey, etc., directly manipulating the storage files (registry entries for Windows, plist files for macOS, etc.) is not recommended as it could lead to data corruption or unexpected behavior in your game.

It is also important to understand that PlayerPrefs is meant for lightweight data storage and is not secure. Users with access to these paths can easily read or write to the PlayerPrefs data. Therefore, sensitive information should never be stored in PlayerPrefs.

Here's an example of using PlayerPrefs to store and retrieve a high score in Unity:

// To save a high score:
PlayerPrefs.SetInt("HighScore", 1000);
PlayerPrefs.Save(); // this is optional and mainly useful on web platforms

// To retrieve a high score:
int highScore = PlayerPrefs.GetInt("HighScore", 0); // 0 is the default value if not set

Was this content helpful?

Other Common Game Engines Questions (and Answers)

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost