Skip to main content

PlayerPrefsSaver

Important Attention Reminder

Coding Style wiki​


PlayerPrefsSaver is the built-in runtime saver of the SaverSystem (inherits Saver). It uses UnityEngine.PlayerPrefs as the storage backend, and every Save* automatically calls PlayerPrefs.Save() to write immediately; the base class text-content data feature (Data Map) is available directly.

NamespaceOxGKit.SaverSystem
Typepublic class PlayerPrefsSaver : Saver
SourcePlayerPrefsSaver.cs
using OxGKit.SaverSystem;

Quick Start​

using OxGKit.SaverSystem;

// Create a runtime saver (PlayerPrefs backend)
Saver saver = new PlayerPrefsSaver();

// Basic access
saver.SaveString("name", "michael");
saver.SaveInt("language", 2);
saver.SaveFloat("bgmVolume", 0.8f);

// Text-content data feature (provided by the Saver base class)
saver.SaveData("appPrefs", "lastLogin", "2026-07-29");
string lastLogin = saver.GetData("appPrefs", "lastLogin", null);

General Rules​

Scope​

SaverStorage BackendScope
PlayerPrefsSaverUnityEngine.PlayerPrefsRuntime (in-game settings, stored per application/platform)
EditorPrefsSaverUnityEditor.EditorPrefsEditor only (editor tool preferences)

(See the Module Intro for an overview)

Write Timing​

Attention Every Save* automatically calls PlayerPrefs.Save() to write to disk immediately; DeleteKey / DeleteAll do not call Save() additionally (by Unity default they are written on normal application quit — call PlayerPrefs.Save() yourself if needed).

Reminder The PlayerPrefs storage location differs per platform (e.g., the registry on Windows, browser IndexedDB on WebGL); on WebGL persistence relies on the browser flushing, and avoid storing huge strings.


Overridden Members​

Method Overview​

MethodDescription
SaveStringSaves a string and writes immediately.
GetStringGets a string.
SaveIntSaves an int and writes immediately.
GetIntGets an int.
SaveFloatSaves a float and writes immediately.
GetFloatGets a float.
HasKeyChecks whether a key exists.
DeleteKeyDeletes a key.
DeleteAllDeletes all PlayerPrefs keys.

SaveString​

public override void SaveString(string key, string value)

Saves a string via PlayerPrefs.SetString, then calls PlayerPrefs.Save() immediately to write.

saver.SaveString("name", "michael");

GetString​

public override string GetString(string key, string defaultValue = "")

Gets a string via PlayerPrefs.GetString; returns defaultValue when the key does not exist.

SaveInt​

public override void SaveInt(string key, int value)

Saves an int via PlayerPrefs.SetInt, then calls PlayerPrefs.Save() immediately to write.

GetInt​

public override int GetInt(string key, int defaultValue = 0)

Gets an int via PlayerPrefs.GetInt; returns defaultValue when the key does not exist.

SaveFloat​

public override void SaveFloat(string key, float value)

Saves a float via PlayerPrefs.SetFloat, then calls PlayerPrefs.Save() immediately to write.

GetFloat​

public override float GetFloat(string key, float defaultValue = 0f)

Gets a float via PlayerPrefs.GetFloat; returns defaultValue when the key does not exist.

HasKey​

public override bool HasKey(string key)

Checks whether the specified key exists via PlayerPrefs.HasKey.

DeleteKey​

public override void DeleteKey(string key)

Deletes the specified key via PlayerPrefs.DeleteKey.

DeleteAll​

public override void DeleteAll()

Deletes keys via PlayerPrefs.DeleteAll.

Important PlayerPrefs.DeleteAll deletes ALL PlayerPrefs keys of this application (including keys not stored through this saver) — use with caution.