Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);
        file.Close();
    }
}

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?

share|improve this question
    
No longer works in what way? Are you getting an error? – Byte56 Dec 19 '13 at 22:39
    
From session to session with the game you cannot have a save load, it reverts back to if a there was no save file. – Tucker Morgan Dec 19 '13 at 22:40
    
"From session to session with the game you cannot have a save load", well yes, if the file isn't writing, you couldn't load it. "it reverts back to if a there was no save file"... huh? – Byte56 Dec 19 '13 at 22:45
    
I have a system where it checks to see if there is a save file, if not it loads so other data a creates a new save file. So it is not saving every time you start the game it creates a new save file. My problem is that it cannot find the XML file to save to. – Tucker Morgan Dec 19 '13 at 22:49
    
If you want to see this and other methods of saving and loading data then there is a paid course you can get for FREE on Udemy. It covers 5 different methods to save and load data in Unity3D. It covers PlayerPrefs, Text files, Binary Serialization, Xml Serialization and even SQLite! The free coupon link for this course is udemy.com/saving-and-loading-game-data-in-unity3d/… Goodluck! – Mike Hunt Apr 11 '16 at 11:52

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.

share|improve this answer

It's faster to debug in the Editor, so this made my life simple:

#if UNITY_EDITOR
rootFolder = Application.dataPath+"/RootFolder/";
#elif UNITY_ANDROID || UNITY_IOS
rootFolder = Application.persistentDataPath;
#endif

And from the rootFolder, you build your file system structure (cross-plateform).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.