0
\$\begingroup\$

I'm attempting to save player data into a Saves folder like so:

string relPath = "Saves/saveData.txt";
FileInfo file = new FileInfo(relPath);
file.Directory.Create();
// File.WriteAllText(relPath, JsonUtility.ToJson(data));

The issue I'm having is that file.Directory.Create(); works on my PC (Windows 11) but not on my Android device. Am I missing something, maybe in build settings or maybe permissions on the device? Is there a better (i.e. more universal) option for creating a directory?

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

It was a permission issue. Apparently the location the game files exist is readonly, so adding the Saves folder was giving an IOException. The simple solution is to move the saves to Application.persistentDataPath

string relPath = Application.persistentDataPath + "/Saves/saveData.txt";

If that doesn't work, look into this answer on how to setup Application.logMessageReceived so you can catch the general exception, which will offer an actual error message to look into.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .