How to persist data (file system) on universal windows platform?

Unfortunately, the solution shown in this tutorial doesn’t work on universal windows platform:

Any hints how to persist game data on the file system (besides PlayerPrefs)?

I have this exact problem and have been searching on and off for months… In fact it has put me off of unity all together. I have several half made games that have been stopped due to not being able to get the information required. Its either this problem or GameObjects that appear to destroy but do not. I think I’m going over to Unreal…this is pointless searching through posts from 2014. @Cellist1972

Well since this has been bumped here I may as well answer it.

There are 2 main ways to save and Load Data in Unity. One way is playerPrefs, which allows simple saving and loading of variables. You use a setup like this to save the cameras scene and position for example:

    public void Save()
    {
        //-----SAVE-CAMERA-POS-----
        PlayerPrefs.SetInt("saved", 1); // Note there is a save to load from
        PlayerPrefs.SetString("scene", (SceneManager.GetActiveScene()).name); // Save the current Scene name
        PlayerPrefs.SetFloat("x", Camera.main.transform.position.x);
        PlayerPrefs.SetFloat("y", Camera.main.transform.position.y); // Save camera x and y coords
        PlayerPrefs.Save(); // IMPORTANT: Needed to save the variables
}
public void LoadGame()
{
    SceneManager.LoadScene(PlayerPrefs.GetString("scene"));
    Camera cam = Camera.main;
    load = true;
    coords = new Vector2(PlayerPrefs.GetFloat("x"), PlayerPrefs.GetFloat("y"));
}

Now this is fine for Floats, Ints and Strings, but has limited use for full save files. There are 2 ways around this. First, with some clever formatting, you can store other data types as these variables. For example, you can use an int as a sortof Bool, like above, or to store a list, you can convert the list to a string like so:

    public void Save()
    {
        //-----SAVE-INVENTORY------
        List<string> inv = InventoryManager.playerInv;
        int count = 0;
        strInv = "";
        foreach (string item in inv)
        {
            if (count != 0)
            {
                strInv = strInv + "##";
            }
            else strInv = strInv + item;
            count++;
        }
        PlayerPrefs.SetString("Inventory",strInv);
        PlayerPrefs.Save();
    }

This code simply replaces the seperators of a list with a string “##”, so say [fish,key,box] becomes “fish##key##box” which allows it to be stored as a string.


Now the other way of storing information is with Resources and StreamReader/StreamWriter. This allows you to save and load data to and from a text file, image, or any other file you want. To get information from a file, you need to make a folder called “Resources” somewhere in the project Assets Folder. Once you have that, you can place a file, say “Notepad.txt” inside, and then load it like so:

    void Awake()
    {
        GameObject gNotepad = (GameObject.FindGameObjectWithTag("Notepad"));
            notepad = gNotepad.GetComponent<InputField>(); //The Input Field I am going to Load to.
            string path = "Assets/Resources/Notepad.txt";
            StreamReader read = new StreamReader(path); // Used to read from a text file
            notepad.text = read.ReadToEnd(); // Set the field of this object to whatever is read from the text file
            read.Close();
        }

And to Save some text to the file:

        string path = "Assets/Resources/Notepad.txt";
        StreamWriter write = new StreamWriter(path);
        write.Write(notepad.text);
        write.Close();

One last thing, to use StreamReader and Writer, you need:

using System.IO;

Hopefully this helps, just comment if you need anything else @pO-Oq