Search Unity

application.DataPath and Application.persistentDataPath Issue

Discussion in 'Windows' started by MegaMasterX, Nov 21, 2020.

  1. MegaMasterX

    MegaMasterX

    Joined:
    Apr 6, 2014
    Posts:
    12
    Hello there. When accessing Application.dataPath and Application.persistentDataPath, both are not pointing to the proper directories on an Xbox in Developer Mode since about June of this year. I've contacted Microsoft who directed me to Unity as Application.dataPath/PersistentDataPath are Unity Wrappers.

    For example, when calling

    string SaveDirectory = Path.Combine(Application.persistentDataPath, "Save");




    This points to: U:\Users\UserMgr1\AppData\Local\Packages\<Title>\LocalState rather than the proper accessible directory, listed here:


    In order to test this a bit further, I created a 2D application, built it and deployed it to my Dev Mode console with nothing but a TMPro UGUI text and the code is simply:

    void Start()
    {
    gameObject.GetComponent<TextMeshProUGUI>().text = $"Data Path: {Application.dataPath}\n\n Persistent Data Path: {Application.persistentDataPath} \n\n ";
    }


    This yields a UnauthorizedAccessException: Access to the path 'U:\" is denied.

    PlayerPrefs are stored in the proper folder but for some reason, Application.DataPath and PersistentDataPath are pointing to folders that straight up don't exist.

    EDIT: I think I may have solved my own question. The "Save" directory doesn't exist in the LocalState folder.
     
  2. MegaMasterX

    MegaMasterX

    Joined:
    Apr 6, 2014
    Posts:
    12
    Replying here to make sure its seen; The path is correct for persistentDataPath - it just doesn't necessarily point to the same labeled things in the Device portal.

    I created a Save directory check in my save game code that creates the directory if needed and tested it - it works now.
     
  3. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    407
    MegaMasterX likes this.