- Home /
Empty Application.persisentDataPath on Android device causing UnauthorizedAccessException
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.
Answer by mouness2020 · Aug 18, 2016 at 12:40 PM
@LK84 I have same problem after updating unity to version 5.4.. problem in some devices like HTC Lenovo Sony ,,, Samsung works fine,, however if you reboot the device then unity can copy files to Application.persisentDataPath and works fine i think its a bug in unity player 5.4 and this cause to me very big problem.. when using sqlite database because sqlite should copy the database file at start to Application.persisentDataPath directory. first time failed to copy then when rebooting the device copy works fine .
This did the trick for me as well. I had the exact same issue and this even created a problem for Unity's integrated IAP system. I even created a thread for this issue. This surely smells like a Unity bug. http://forum.unity3d.com/threads/system-unauthorizedaccessexception-access-to-the-path-unity-is-denied.426841/
Can you keep me updated how Unity replies on your bug report?
Your answer
Follow this Question
Related Questions
How to send an Email with the details entered in a json file? 0 Answers
System.IO.File does not contain a definition for 'WriteAllLines' 1 Answer
My app generates a binary file but either fails to save data or load it || Unity for Android 1 Answer
How to "create directories" in specific folders 2 Answers
PersistentDataPath saved files are not writing into android device? 1 Answer