Search Unity

Application.persistentDataPath sometimes return null on certain android device

Discussion in 'Android' started by appxplore-tech, Sep 28, 2016.

  1. appxplore-tech

    appxplore-tech

    Joined:
    Jul 4, 2012
    Posts:
    62
    as titled.

    and i found that sometimes after i do a restart on the device the problem solved and i managed to retrieve the path again.

    Is there a way to solve the problem and anyone that facing the same issue?

    Thank you.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    We also see this issue with some of our users. I wonder what can we do to fix it.
     
  3. Arganoid

    Arganoid

    Joined:
    Oct 12, 2013
    Posts:
    24
    I've also started getting this recently.
     
  4. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    Which Unity version do you use? There was an improvement in 5.4.2p1 which should have fixed this. If you are still seeing this issue with 5.4.2p1 or a newer Unity version, please send a bug report and specify device (devices) where it is reproducible.
     
  5. Arganoid

    Arganoid

    Joined:
    Oct 12, 2013
    Posts:
    24
    I am on 5.4.1f1. (Unity says it's up to date, I guess the update releases are staggered?)
     
  6. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Can you elaborate on what the fix is, which devices it applies to, etc.
     
  8. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    The fix is an added fallback to "internal" path. Since Android 4.4 the WRITE_EXTERNAL_STORAGE permission is not required when reading / writing to external cache and persistent data paths (which are app specific paths). However some devices with KitKat and newer Android versions seem to struggle with this and they still don't properly allow to use external cache and persistent data paths if WRITE_EXTERNAL_STORAGE permission is not granted. So with the fix we should fall back to internal paths on such devices.
     
  9. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Thanks for clarifying.

    Is it possible that persistentDataPath will change since the game is first installed ?
    For example, I persist certain data, but on the next load, Unity falls back to the internal path and so it cannot find the previously stored data?

    Also, according to your answer, the fix should only apply in scenarios where WRITE_EXTERNAL_STORAGE was not granted. Is this correct ?
     
  10. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    That's an interesting thought. Personally I haven't seen this happen yet. However it all depends on the device. If a device has an inconsistent behaviour, this might happen. But I think we wouldn't start returning internal path if external was returned before. An opposite is more likely to happen, that at first the internal path is used, but then device starts to allow external path and we switch to it (as you've mentioned in the first post, that the device restart solved the null path issue).
    Yes, that is correct. If the app requires this permission and the permission is granted, then external paths are used on all Android versions and there are no problems.
     
  11. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285