Unity3D Application.persistentDataPath is null on Android

I’ve no idea why this is happening all of a sudden, but the static property Application.persistentDataPath is returning a zero length string and not the path to the storage folder on my Android devices.  From googling, I can see I’m not the only one with this problem.  It’s happening whether I build directly from Unity, or download it from the beta tab on Google Play.

I added the following method to my Android plugin JAR so at least I could move on and not get stuck:

    public static String PBgetFilePath(final Activity activity)
    {
        File path = activity.getApplicationContext().getFilesDir();
        Log.i(LOGTAG,"Internal FilesDir: " + path.getPath());
        return path.getPath();
    }

This returns the correct string and when I use it, I can read and write files as expected.  If persistentDataPath returns a null or a zero length string, then I call my java code and use the result.

Leave a Reply