Skip to main content

PlayerPrefs and SaveData

Polygon Engine stores project data in one 8,192-byte Memory Card block on Port

  1. Editor Play Mode uses a JSON mirror with the same fixed entry and string limits. Use PlayerPrefs for typed gameplay settings and progress; use SaveData when a system deliberately needs raw string storage.

Limits

ItemLimit
Total entries32
Physical key31 bytes plus terminator
Value63 bytes plus terminator
Memory Card allocationOne block
Active cardPort 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

MethodPurpose
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.