I am very new to unity. I am trying to make myself an app to store the completion of my shiny living dex. I have a script which reads and writes a column of roughly 1k ones and zeros, to store whether or not I have the shiny Pokemon. I also have a csv file which is read only, which stores the names and Pokedex numbers of every Pokemon, as well as a useless 0, stored in the format of “(Pokemon name), (Pokedex number), 0”.
My issue is that whenever I build the apk or restart the installed app, the csv files don’t seem to save. Whenever I restart the app, the states of the Pokemon aren’t saved, and the text objects that the names and numbers get written to don’t change at all. They work perfectly in the editor. I couldn’t figure out if there was a way to view the files on the phone, I checked in the file manager but couldn’t find anything.
Could you show the code that writes the files?
private bool ReadIsShinyFromCSV(int index)
{
string csvFilePath = Path.Combine(Application.dataPath, “PokemonData.csv”);
if (!File.Exists(csvFilePath))
{
return false;
}
string[ ] csvLines = File.ReadAllLines(csvFilePath);
if (index >= 0 && index < csvLines.Length)
{
if (int.TryParse(csvLines[index], out int isShinyValue))
{
return isShinyValue == 1;
}
}
return false;
}
private void WriteIsShinyToCSV(int index, bool isShiny)
{
string csvFilePath = Path.Combine(Application.dataPath, “PokemonData.csv”);
if (!File.Exists(csvFilePath))
{
return;
}
string[ ] csvLines = File.ReadAllLines(csvFilePath);
if (index >= 0 && index < csvLines.Length)
{
csvLines[index] = isShiny ? “1” : “0”;
File.WriteAllLines(csvFilePath, csvLines);
}
else
{
Debug.LogError(“Sprite data not found in PokemonData.csv file!”);
}
}
Application.dataPath is a read-only directory, you should not be overwriting files in there in your game. Application.persistentDataPath is for that.