I am a beginner making games with Unity.
I am making a function to save, read and write json format data
The reading part just doesn't work.
-The file has been written.
・ It will be initialized when reading, and will not be in the expected state.
I found the location of the file using Application.persistentDataPath and checked it. If i check after the program is finished, it will contain the changed data, but the next time you start the program, the contents of the file will be initialized and the original data will be lost.
public void SavePlayerData (Player player)
FileStream fs = File.OpenWrite (Application.persistentDataPath + "/savedata.json");
string jsonstr = JsonUtility.ToJson (player);
writer = new StreamWriter (fs);
public Player loadPlayerData ()
string datastr = "";
FileStream fs = File.OpenRead (Application.persistentDataPath + "/savedata.json");
reader = new StreamReader (fs, Encoding.UTF8);
datastr = reader.ReadToEnd ();
I would be pleased if anyone could tell me how I could read the stored data without initializing it.
Answer # 1
You probably erased the file when you started the program.
But I can't say anything because the presented code doesn't include that much
- file reading does not work in c language
- unity data synchronization
- ruby - saved data does not appear in the view
- reading csv file in python
- post of php image file does not succeed
- c - about file reading
- reading and writing php data
- java - add data to json file using jackson
- php file does not run well
- css file does not reflect in html
- unity - debuglog does not respond
- does the file name have an index?
- ruby - csv file reading in rails
- html - esp8266/the specified file does not open
- unity - script invalidation does not work
- spring - image file specification does not work
- save one data to a file
- about reading files
- reading python files