Playerprefs or Binary ? (Mobile singleplayer platformer game) [Android]

Which one is recommended to use for saving the game?

Depends. In general PlayerPrefs (as the name suggest) developed for saving preferences (settings). If you have a small chunk of data, you may use it. Otherwise, save it in binary or in other format.

What is your definition for small chunk of data?

< 1 kilobyte

To give you an idea, here’s the registry for my game:

Note that on Windows, the registry is where ‘PlayerPrefs’ gets stored. For more info on that:

Of the settings in there, the Screenmanaer one’s are Unity specific… Unity has created those. Same with the “unity.cloud” and “unity.player” and other “unity*” ones.

The first 7 values (ignored default) are my custom ones.

All 7 of them are simple single value things. All being really ints and or floats (note the ‘invalid dwords’ are floats, it doesn’t know how to represent them well in regedit).

They represent merely preferences. When they start the game they can go into ‘settings’ and pick things like game quality, input settings, various graphics modes and brightness. This is where I store these values. They’re completely independent of a game save… it’s how the game should ‘look/feel’ on this machine when it starts up.

My save files on the other hand go into their appdata folder (for windows that is), that being the ‘Application.persistentDataPath’:

here I put save files in json. Though the format is whatever you’d like. You could use binary, xml, bson, ini, whatever. I just json because I like it. The serializer I use is my custom formatter that I insert into the .net serialization engine (same ruleset as .net binaryserializer, just to a json format):

The files look a bit like this:

{
    "@type" : "com.mansion.SaveGameToken",
    "Data" : [
        "System.Object[]",
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "*Ep2*GameState*",
            "Value" : {
                "@type" : "com.mansion.Scenarios.Episode2.Episode2Controller+Token",
                "ObjectivesToken" : [
                    "com.mansion.Objective[]",
                    {
                        "@type" : "com.mansion.Objective",
                        "Message" : "Find a way around."
                    }
                ],
                "Statistics" : {
                    "@type" : "com.mansion.Statistics.Ledger",
                    "EP2_ALLWEAPONS" : 3,
                    "EP2_ALLWEAPONS*|*FlashlightInventoryItem" : 1,
                    "EP2_ALLWEAPONS*|*MurielsShovelInventoryItem" : 1,
                    "EP2_ALLWEAPONS*|*SledgehammerInventoryItem" : 1,
                    "SavedGame" : 1
                },
                "CurrentTime" : {
                    "@type" : "System.TimeSpan",
                    "_ticks" : 609900000
                },
                "Difficulty" : 2
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "08D5A48D1313C2D2*playerstate",
            "Value" : {
                "@type" : "com.mansion.Scenarios.PlayerScenarioPersistentStateController+PlayerStateToken",
                "Health" : 125,
                "MaxHealth" : 125,
                "Inventory" : [
                    "System.Object[]",
                    "FlashlightInventoryItem",
                    "UntrackedToken - NewGame+",
                    "UntrackedToken - Enemy - Husk",
                    "MurielsShovelInventoryItem",
                    "SledgehammerInventoryItem",
                    "FlashlightClipOnInventoryItem",
                    {
                        "@type" : "com.mansion.Entities.Inventory.InventoryPouch+Token",
                        "name" : "UntrackedToken - FuseWestTrail",
                        "token" : false
                    },
                    {
                        "@type" : "com.mansion.Entities.Inventory.InventoryPouch+Token",
                        "name" : "UntrackedToken - FuseGreenhouse",
                        "token" : false
                    },
                    {
                        "@type" : "com.mansion.Entities.Inventory.InventoryPouch+Token",
                        "name" : "UntrackedToken - FuseCourtyard",
                        "token" : false
                    },
                    "Inv - VideogameHandheld",
                    "Inv - Fuse",
                    6
                ],
                "AmmoToken" : [
                    "com.mansion.Entities.Weapons.AmmoPouch+ValuePair[]"
                ],
                "ImmuneToGrapple" : false,
                "CurrentEquippedWeaponItem" : "MurielsShovelInventoryItem"
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "*SceneVariables",
            "Value" : {
                "@type" : "com.spacepuppy.Dynamic.StateToken",
                "ThreatLevel" : 0,
                "OvertimeProgress" : 0,
                "JustEnteredNewRoom" : false
            }
        },
        "08D66C4CEB7E2C77",
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "FuseSafe-AlwaysOpen",
            "Value" : 2
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "08D633F2AC90AAFC",
            "Value" : {
                "@type" : "com.mansion.Cutscenes.CutsceneSequenceManager+Token",
                "SequenceIndex" : 0
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "08D63217544C4790",
            "Value" : {
                "@type" : "com.mansion.Cutscenes.CutsceneSequenceManager+Token",
                "SequenceIndex" : 1
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "08D631FCB6C52DD5",
            "Value" : {
                "@type" : "com.mansion.Cutscenes.CutsceneSequenceManager+Token",
                "SequenceIndex" : 0
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "08D6319966F78D68",
            "Value" : {
                "@type" : "com.mansion.Cutscenes.CutsceneSequenceManager+Token",
                "SequenceIndex" : 0
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "08D630D246ED8070",
            "Value" : {
                "@type" : "com.mansion.Cutscenes.CutsceneSequenceManager+Token",
                "SequenceIndex" : 3
            }
        },
        {
            "@type" : "com.mansion.ScenarioPersistentData+ValuePair",
            "Id" : "*Ep2_FuseBox*",
            "Value" : 0
        }
    ],
    "Checkpoint" : {
        "@type" : "com.mansion.CheckpointState",
        "Scene" : "Outdoor_Hub",
        "Position" : {
            "@type" : "UnityEngine.Vector3",
            "x" : 0.119993507862091,
            "y" : 2.20000004768372,
            "z" : 10.5
        },
        "Rotation" : {
            "@type" : "UnityEngine.Quaternion",
            "x" : 0,
            "y" : 1,
            "z" : 0,
            "w" : -6.55651001579827E-06
        },
        "Aux" : {
            "@type" : "com.spacepuppy.Geom.Trans",
            "Position" : {
                "@type" : "UnityEngine.Vector3",
                "x" : 0.22099857032299,
                "y" : 2.14823341369629,
                "z" : 12.6479997634888
            },
            "Rotation" : {
                "@type" : "UnityEngine.Quaternion",
                "x" : 0,
                "y" : -1,
                "z" : 0,
                "w" : 2.95042946163449E-06
            },
            "Scale" : {
                "@type" : "UnityEngine.Vector3",
                "x" : 1,
                "y" : 1,
                "z" : 1
            }
        }
    }
}

Or those stats files look a bit like this:

{
    "@type" : "com.mansion.Statistics.Ledger",
    "EP1_SECRETENDING" : 1,
    "EP1_SKELETONKEY" : 1,
    "EP1_BEATGAME" : 1,
    "EP1_OVERTIME" : 1,
    "EP1_BUGSPRAY" : 1,
    "Deaths" : 24,
    "TakeDamage" : 729,
    "SavedGame" : 150,
    "EP1_KILLALLKITTIES*|*G" : 7,
    "EP1_SAVEALLKITTIES" : 1,
    "RoundsFired" : 2384,
    "MobsKilled" : 297,
    "TimesHealed" : 3,
    "MobsKilled*|*Zombie" : 116,
    "EP1_KILLALLKITTIES*|*A" : 5,
    "EP1_KILLALLKITTIES*|*E" : 7,
    "EP1_FULLYLOADED*|*B" : 11,
    "EP1_TANKCONTROLS" : 1,
    "ACH-EP2_HANKENFISCH" : 1,
    "SRanked" : 1,
    "EP1_FULLYLOADED" : 1,
    "ACH-EP1_SRANK" : 1,
    "ACH-EP1_FULLYLOADED" : 1,
    "ACH-EP1_SKELETONKEY" : 1,
    "ACH-EP1_BEATGAME" : 1,
    "EP1_FULLYLOADED*|*A" : 2,
    "EP1_FULLYLOADED*|*C" : 1,
    "EP1_SRANK" : 1,
    "EP1_KILLALLKITTIES*|*B" : 2,
    "EP1_KILLALLKITTIES*|*D" : 2,
    "ACH-EP2_GARDENERSJOURNAL" : 1,
    "ACH-EP2_DRNOTE" : 1,
    "ACH-EP2_BEATGAME" : 1,
    "ACH-EP2_TUNASHED" : 1,
    "ACH-EP2_NOINVSLOTS" : 1,
    "ACH-EP2_CLONEHALL" : 1,
    "EP1_KILLALLKITTIES*|*C" : 1
}
4 Likes