Hi all,
Im making a PSVita game (not PSM) and I want to be able to save data in a file to later recover it (like to let player make custom track or anything that requires a lot of data), I have tried streamingassets folder and persistent data path, none seem to work, well I think streaming assets is read only or results shows that, I use streamreader and streamwriter for file access, could anyone please tell me how can I achieve this? I believe the problem might be the folder rather than the functions used, in the docs I cant find a good way to do this nor is told anywhere as far as i can see but of course it has to be written somewhere. Thanks a lot beforehand for any clue
This is what I use, mind you I have not worked with PSVita, but I believe it should work.
using UnityEngine;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public static class StorageSystem
{
public static void SaveData<T>( T _data, string _fileName )
{
string _path = Application.persistentDataPath + _fileName;
BinaryFormatter _formatter = new BinaryFormatter();
FileStream _stream = new FileStream( _path, FileMode.Create );
_formatter.Serialize( _stream, _data );
_stream.Close();
}
public static TypeOfData LoadData()
{
string _path = Application.persistentDataPath + "/mydata.data";
if( File.Exists( _path ) )
{
FileStream _stream = new FileStream( _path, FileMode.Open );
BinaryFormatter _formatter = new BinaryFormatter();
TypeOfData _data = _formatter.Deserialize( _stream ) as TypeOfData;
_stream.Close();
return _data;
}
else
{
Debug.LogError("File not found in " + _path);
return null;
}
}
}
EDIT: I forgot to mention that the data types that you save must be serializable. [System.Serializable] public class MyClass{}
Thanks for sharing your snippet, I think its quite clever strategy, however its not working for me in the Vita, in PC it works perfect. I tried also replacing the persistent data path with the Streaming assets folder and still didnt work (in pc it works with both folders), Im open to other ideas or folders that we could try to store file in, as said I have the feeling the biggest issue is the folder is not the right one, I heard player prefs work for PSM but well I didnt even try that as I want to store files and in player prefs as far as I know one can only store individual values or arrays isolated. As said feel free to suggest other methods or folders to achieve this =)
Hello! Did you find a solution?
I’m not able to make a file in my psvita with unity too
PlayerPrefs doesn’t work too…
Hi all,
For PlayerPrefs users I use “PlayerPrefs.Save()” method during gameover.
That’s all!
When the game restart the new values are loaded.
I do’nt know where the PlayerPrefs are saved but it works!
I will investigate where they are stored.
Enjoy!