Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

System.UnauthorizedAccessException - "Access to the path /Unity is denied"

Discussion in 'Scripting' started by Freaking-Pingo, Aug 20, 2016.

  1. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
    Hi Uniteers, we are encountering an error when building for Android. We are receiving the following error:
    System.UnauthorizedAccessException - "Access to the path /Unity is denied". We are running Unity 5.4.0f3 and are using "Internal only" for write access. We are saving using Application.persistentDataPath. We haven't tested iOS or External (SDCard) for write access. Game runs fine in editor. Additionally, Unity integrated IAP system is having problem saving cache data, because of this error.

    Anyone have an idea? I have never encountered this problem before. My best hunch is that it is a Unity 5.4 error, based on a recent google search find, I found this recent submitted error: http://pastebin.com/vLBFk6U7.
     
    MayhemMike likes this.
  2. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
    No takers? I haven't yet found a solution for this. It appears that if I set write access to SDcard the problem is resolved, however, this is not ideal.
     
  3. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
    I'll take it back. Setting Write Acces to SDcard produces similar issues. We are pretty stuck at this point.
     
  4. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
  5. arodes

    arodes

    Joined:
    Sep 8, 2015
    Posts:
    5
    We are receiving the same error since Unity 5.4. Seems like a bug. Did you already submitted a bug report?
     
  6. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
    I submitted a bug report, but I am not sure if I did it properly. I hope they will respond if they find my report inadequate.
     
  7. do2

    do2

    Joined:
    May 30, 2014
    Posts:
    4
    Hi. I'm having the exact same problem as you describe after upgrading to Unity 5.4.1f1. Were you able to find a solution? Or at least were you able to submit a bug report correctly?
     
  8. greenalice

    greenalice

    Joined:
    May 16, 2014
    Posts:
    13
    Same bug here for Unity 5.4.1f1
     
  9. MayhemMike

    MayhemMike

    Joined:
    Oct 23, 2013
    Posts:
    46
    Seems I'm having the same issue but I can hardly advise my users to restart their devices :-/

    Did you guys find a workaround for the bug?
     
  10. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
    Alright, as far as I have observed, this appears to only be a problem for certain devices. My old HTC One have not always had this problem, but after some update of Unity I have had this issue. I never found a solution to this, but apparently, I am also one of the only people experiencing this issue.
     
  11. kustom

    kustom

    Joined:
    May 11, 2012
    Posts:
    73
    i have experienced it just today and i cant find a solution... it work si f i set in PlayerPrefs 'Write Permission' to External (SDCard), but i don't want users have to give this kind of permission.

    Update: After reseting my Android device it seems to work again, not a fair solution but enough for me right now
     
    Last edited: Jan 14, 2017
  12. lassade

    lassade

    Joined:
    Jan 27, 2013
    Posts:
    59
    I got this bug in today.

    Here's what happen:
    0. Installed an release version.
    1. Installed an development version of my app
    (this dev version wiped my game data clean)
    2. Switch back to a release version.
    (do not cleared any data)
    4. Got UnauthorizedAccessException.

    I tested this with a blank project. Bug confirmed, at least for me. Using 5.4.1f1, if some one don't mind please test with the newer versions. (The project is attached)

    Any ideas why this happend?
     

    Attached Files:

    Freaking-Pingo likes this.
  13. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    298
    I tried using the example project and your guide, but I couldn't reproduce the bug in 5.5.1f1
     
  14. hjalle

    hjalle

    Joined:
    Mar 15, 2016
    Posts:
    4
    We used to run into this problem on some certain devices, so we are using this workaround, and are now seeing 0 problems related to this (on android).

    private static string GetAndroidFriendlyFilesPath()
    {
    #if UNITY_ANDROID
    AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
    AndroidJavaObject applicationContext = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
    AndroidJavaObject path = applicationContext.Call<AndroidJavaObject>("getFilesDir");
    string filesPath = path.Call<string>("getCanonicalPath");
    return filesPath;
    #endif
    return Application.persistentDataPath;
    }

    private static string GetAndroidFriendlyCachePath()
    {
    #if UNITY_ANDROID
    AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
    AndroidJavaObject applicationContext = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
    AndroidJavaObject path = applicationContext.Call<AndroidJavaObject>("getCacheDir");
    string filesPath = path.Call<string>("getCanonicalPath");
    return filesPath;
    #endif
    return Application.temporaryCachePath;
    }
     
    justtime, lassade and onderadasigma like this.
  15. MasterFlu

    MasterFlu

    Joined:
    Jul 12, 2012
    Posts:
    1
    Thank you very much hjalle!!!! Your solution worked like a sharm :)
     
  16. calebbbarton

    calebbbarton

    Joined:
    Mar 20, 2018
    Posts:
    8
    Hi,

    Our project is having the same problem except on IOS devices instead of Android. This is on an Iphone 7+ on the latest OS. Our storage external in Unity. We can save text files fine, however trying to save an image gets denied.

    The image saving is simply converting a texture2D into a byte array and using File.WriteAllBytes to the directory.

    Our .csv files are saving to "Application.persistantDataPath + MyProject/Saves/filename.csv", while our images are saving to "Application.persistantDataPath + MyProject/Images/images.png" (myproject name changed for privacy)

    Thanks
     
  17. bz_tian

    bz_tian

    Joined:
    Jun 28, 2018
    Posts:
    4
    I had the same problem - but I noticed I had created the folder via windows as I thought about the permission system - i can see why it might give an error.. So I went ahead and deleted the folder, then had my program in Unity create it instead.. now there are no problems.. Here's a sample of the working code:

    string s_saveFolder = "Assets/Sales/Saves/";
    try
    {
    if (!Directory.Exists(s_saveFolder))
    {
    Directory.CreateDirectory(s_saveFolder);
    }

    DirectoryInfo dir = new DirectoryInfo(s_saveFolder);
    FileInfo[] info = dir.GetFiles("*.txt");
    foreach (FileInfo f in info)
    {
    Debug.Log("readying in files: " + f.Name);
    }
    }
    catch (IOException ex)
    {
    Debug.Log("IOException ex" + ex.Message + " ... " + ex.StackTrace);
    System.Console.WriteLine(ex.Message);
    }
     
  18. bz_tian

    bz_tian

    Joined:
    Jun 28, 2018
    Posts:
    4
    NOTE -- i DID create the 'Sales' folder off of Assets via the Windows file system (if I remember correctly).. If there's a problem still for yours, perhaps create the folder via the Unity Projects window...
     
  19. Shubhamprinz

    Shubhamprinz

    Joined:
    Jul 20, 2018
    Posts:
    1
    The solution is to Build and Save the apk in the project folder and file name with "MyGame.apk" (That worked for me)