Hey, I ran into the following strange problem. My game, which is working fine on the Editor and Unity remote suddenly started to crash on my Android device in the middle of the game. It actually crashed when I tried to save same User Input on the Application.persistentDataPath. Here is my code:
static void Save()
{
string filename = "/filename.dat";
BinaryFormatter bf = new BinaryFormatter();
Debug.Log("path: "+Application.persistentDataPath+filename);
FileStream file = File.Create(Application.persistentDataPath+filename);
bf.Serialize(file, UserInputStuff);
file.Close();
}
I used Log Viewer fro the asset store to be able to read my Debug Messages on my device. The output from my Debug.Log is “path: /filename.dat”.
This leads to the UnauthorizedAccessException “Access to the path “/filename.dat” is denied”
For some strange reason the persistenddatapath is empty. Weird thing, it used to work before, maybe my Unity update to 5.4 messed it up. The Android OS is 5.0.1
Anyone has an idea?
@UPDATE:
Tested it on my girlffriends smartphone. worked fine there. Seems to be a device specific issue. Still worries me. What if I publish the game and user with the same smartphone settings experience the same issues and gonna rate my game badly. How can I make the game “more robust”? Try, catch doesn’t really work for me here.