Saving Using XmlSerializer and PlayerPrefs

I have a save system for my game state that seems to be working. Just want to know what (if any) are the downsides to this technique. Details below:

To save:

-Serialize my game state to an xml string
-Save xml string to PlayerPrefs.

To load:
-Read xml string from PlayerPrefs
-Deserialize into my GameState object.

Like I said, this is all working great right now. I had been saving to/from a file rather than PlayerPrefs but I switched to PlayerPrefs in anticipation of using something like Prime31’s iCloud plug-in which uses PlayerPrefs.

Here is the code:

public void LoadGameState()
	{
		if(PlayerPrefs.HasKey("GameState"))
		{
			//load state
			XmlSerializer xmlSerializer = new XmlSerializer(GameState.GetType());
			StringReader stringReader = new StringReader(PlayerPrefs.GetString("GameState"));
			GameState = (GameState)xmlSerializer.Deserialize(stringReader);
		}
		else
		{
			//create new
			GameState = GameState.CreateNew();
			SaveGameState();
		}
		
		CurrentWorld = GameState.Worlds[0];
		CurrentLevel = GameState.Worlds[0].Levels[0];
	}
	
	public void SaveGameState()
	{
		XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(GameState.GetType());
		StringWriter stringWriter = new StringWriter();
		
		xmlSerializer.Serialize(stringWriter, GameState);
		Debug.Log("Save state to player prefs");			
		PlayerPrefs.SetString("GameState",stringWriter.ToString());		
	}

The one downside is that you will not be able to use micro framework stripping level, building for iOS. There is no System.Xml API in micro framework.

I have a similar system but use JSON. I also save out a checksum in an effort to make it less prone to tampering.

I’m ok with not using the micro framework stripping… my game should still come in well under the min allowed by iPhone/iPad.

If that is the only downside, I’m good to go.

Thanks!

I have used the out-of-box .NET XML serialization in iOS project - everything worked fine, but eventually I had to switch to JSON because of Micro framework.