Save Games (General Approach)

I’m getting close to finishing a couple games, and one of them requires save games to be fully functional. The problem is that there’s way too much information to be stored in PlayerPrefs.

Is there any way to output info to a text file and grab it again? I’d take any technique, really. It just has to store the information locally.

Here’s the information it needs to store:
Player Stats (Abilities, stats, points remaining, specialty)
Player Money
Shop Inventory
Control zones for twenty factions
Current plans for twenty factions
Player’s standing with twenty factions
All items purchased
Saved battle configurations
Unlocked items, weapons, armor, and vehicles
Time spent playing so far
Tower customized particle effects

I’m just gonna go ahead and plug myself shamelessly here…

(The current version is not well suited to your needs, but the new version is finished and ready to go as soon as Unity 2.5 is released and would probably be easy for you to use.)

Or you could use Serialization?

Ah well. If worse comes to worse I can just convert every last piece of that information into a single space-divided string and call PlayerPrefs once. If I have a function for writing a string, it shouldn’t be too hard to write a function for decoding it.

I’m a tad averse to spending money, even when it’s just in the hundreds of dollars. I’m just a poor college student, after all.

Welcome to the world of INDIE game dev, my friend.

For most games, however, PlayerPrefs is perfectly acceptable.

(I might get this to save space and make in game cut scenes into text files, instead of taking videos. Thanks!)

I’m sick and tired of people referencing PlayerPrefs and not EXPLAINING HOT TO USE IT!

The examples in the docs explain pretty much all you need to know; there really isn’t anything to it.

// Do this to save the player's high score,
// like maybe in a GameOver routine
PlayerPrefs.SetInt("PlayerHighScore", highScore);

// Do this to read the player's high score,
// like maybe in a Start function
highScore = PlayerPrefs.GetInt("PlayerHighScore");

–Eric

vaguely following…

Basically, set a name for the location you’re storing the data and store it in a variable. (I like “Save1” to “Save9”) Then send it to playerprefs using the location and get it once the game is started.

In my case, if my entire save game is a formatted String, I’d just use PlayerPrefs.SetString(saveLocation, stringName).

In order to load the game, I’d use saveGame = PlayerPrefs.GetString(saveLocation).

On the screen where the player can choose a slot to load, I’d get each string in turn and test them to see if they were populated. If they were, I’d gather the info displayed on the slot (name given to save slot, time spent ingame, current level, etc…) and set that to local variables in order to avoid having to call it or parse it multiple times.

could you post an example UnityPackage ?

That’ll have to wait until I get my test parsing to work properly.