How to write to a file from a built Unity Game
Hello, I am trying to log game data from my unity game so I can analyze it later. The following code functions (it creates and writes to the intended file) when running the game in the editor, however when I build the game, my logging file fails to be created. This is how i save my logged information.
public void SaveCSV()
{
string[][] output = new string[rows.Count][]; // my data is held in rows (List<string[]>)
//Convert rows into string [][]
for (int i = 0; i < output.Length; i++)
{
output[i] = rows[i];
}
int len = output.GetLength(0);
string divider = ",";
StringBuilder sb = new StringBuilder();
//convert output into csv format
for (int index = 0; index < len; index++)
sb.AppendLine(string.Join(divider, output[index]));
string filePath = getPath(); //Returns Application.persistentDataPath + "/gameData.csv"
//Save Data
StreamWriter outStream = File.CreateText(filePath);
outStream.WriteLine(sb);
outStream.Close();
}
Do I have to do something differently to get this function to save the .csv file from a built unity game?
Any help would be appreciated.
Thanks
Your answer
Follow this Question
Related Questions
Get Debug.Log output in the working iOS build 5 Answers
Why are my sprites glitching and flashing in build? 2 Answers
Fullscreen canvas shrinks to half size in build only? 0 Answers
UI Scrollview dissapearing in Build? 5 Answers
How do I make sure all C# system system files are gone when I build. 1 Answer