PlayerPrefs and SaveData
Polygon Engine stores project data in one 8,192-byte Memory Card block on Port
- Editor Play Mode uses a JSON mirror with the same fixed entry and string
limits. Use
PlayerPrefsfor typed gameplay settings and progress; useSaveDatawhen a system deliberately needs raw string storage.
Limits
| Item | Limit |
|---|---|
| Total entries | 32 |
| Physical key | 31 bytes plus terminator |
| Value | 63 bytes plus terminator |
| Memory Card allocation | One block |
| Active card | Port 1 |
For PlayerPrefs, use keys of up to 28 bytes and strings of up to
61 bytes. These limits count UTF-8 bytes, so accented characters can use
more than one byte. Typed and raw values share the same 32-entry store.
PlayerPrefs
SetInt, SetFloat, and SetString return false when a value cannot be
encoded. Their getters accept an optional default. HasKey, DeleteKey, and
DeleteAll manage only PlayerPrefs entries; DeleteAll does not erase raw
SaveData keys. Save flushes the complete store.
function CompleteChapter(gameObjectId)
if not PlayerPrefs.SetInt("chapter", 2) or not PlayerPrefs.Save() then
Log.Print("Save failed: " .. SaveData.GetLastError())
end
end
function Start(gameObjectId)
local chapter = PlayerPrefs.GetInt("chapter", 0)
local volume = PlayerPrefs.GetFloat("volume", 1.0)
local language = PlayerPrefs.GetString("language", "en")
end
SaveData
| Method | Purpose |
|---|---|
SaveData.Write(key, value) | Changes one raw string value in memory. |
SaveData.Read(key) | Returns a raw string or nil. |
SaveData.Flush() | Persists the complete in-memory store. |
SaveData.Clear() | Clears all typed and raw entries in memory. |
SaveData.Reload() | Reads the platform store; check success before using the result. |
SaveData.GetLastError() | Returns the latest persistence diagnostic. |
Always check PlayerPrefs.Save, SaveData.Flush, and SaveData.Reload. Show a
player-facing success or failure state, and never assume a card is present,
formatted, writable, or has a free block.
Use View > Save Data Simulator to inspect payload usage and simulate an absent, full, or corrupt card before building. Configure a unique Save File ID and a readable Display Title in Project Settings for your game.
Saving and loading progress
Setters change the current values. Call PlayerPrefs.Save() or
SaveData.Flush() to save them, and check the result before showing a success
message. If saving fails, offer a retry and keep the player's progress available.
Use SaveData.Reload() when the player chooses to load their last save. Check
its result before moving the player or applying saved settings. A successful
load replaces unsaved changes. The Two-Room Relay tutorial
shows a complete save, load, reset, and retry flow.