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:
- Windows: Data is saved in the registry under a subkey of
HKEY_CURRENT_USER\Software\[CompanyName]\[ProductName]
, where[CompanyName]
and[ProductName]
are the company and product names you've set in your project settings.
Registry Example: HKEY_CURRENT_USER\Software\MyCompany\MyGame
- macOS: PlayerPrefs are stored in
~/Library/Preferences/folder
, the folder being named as the reverse DNS style bundle identifier (com.company.product
).
File Example: ~/Library/Preferences/com.mycompany.mygame.plist
- Linux: Data is stored in
~/.config/unity3d/[CompanyName]/[ProductName]
.
File Example: ~/.config/unity3d/MyCompany/MyGame/prefs
-
Android: PlayerPrefs uses
SharedPreferences
. The data is saved in an XML file in the app's private folder, located at/data/data/pkg-name/shared_prefs/pkg-name.xml
, wherepkg-name
is your application's package name. -
iOS: PlayerPrefs data is stored in
NSUserDefaults
and is backed by a.plist
file within the app's sandbox. -
WebGL: PlayerPrefs data is stored in the browser's IndexedDB.
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)
- Can You Use C# in Unreal Engine?
- Is Unreal Engine Open Source?
- Can Unreal Engine make 2D games?
- Does Unreal Engine Use Python?
- What Language Does Unreal Engine Use?
- Does Unreal Engine Use JavaScript?
- Does Unreal Engine work on Linux?
- How Do I Uninstall Unreal Engine 5?
- Is Blender or Unreal Engine Better?
- Does Unreal Engine Work on Mac?
- Why Is Unreal Engine So Laggy?
- Can I Run Unreal Engine 5 Without a Graphics Card?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
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