How can I save an XML file with Unity on the Android platform?

| | August 18, 2015

I am writing a game that has a save function which looks like this

    public void Save()

        System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(this.GetType());
        System.IO.StreamWriter file = new System.IO.StreamWriter(("Assets/Resources/Save");
         ser.Serialize(file, this);

This will work fine in the editor and on Windows machines, but when we build to Android the saving no longer works. Why is that?

One Response to “How can I save an XML file with Unity on the Android platform?”

  1. It’s likely to do with the path you’re trying to save to and/or the permissions. While I haven’t done this myself, all the examples I’ve seen where people are writing to files in Android, they have to use Application.persistentDataPath and append their directory to the end. This ensures you’re writing to the correct location, and a location where you have permission to do so.

Leave a Reply