Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by JustinNSE · Jan 07, 2015 at 01:42 AM · androidsavingnullpersistentdatapath

Application.persistentDataPath returning null on certain Android devices

Recently using some exception handling / crash tracking software I noticed a percentage of users on android devices were throwing a UnauthorizedAccessException when trying to save!

Doing some research I saw a few developers complaining about issues regarding changing paths being returned depending on internal vs external storage so I began logging out what the Application.persistentDataPath was returning on those users throwing the exception.

To my surprise it seems that when I logged out Application.persistentDataPath it was not different paths than expected but actually returning NULL. My save code uses is pretty simple and I create the file path like so:

 string filePath = System.IO.Path.Combine( Application.persistentDataPath, "DI.txt" );

Any idea on how / why / when the Application.persistentDataPath should or would return NULL?

This does not happen to our ios users!!!!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HYPERSAVV · Jan 07, 2015 at 07:59 AM 0
Share

I'm not an Android expert, so I'm not sure entirely how to go about checking this theory out, but can you check the permissions that are set for the Android build? I figured Unity just sets permissions based on what calls are made, but it's worth checking to see if you have the ability to write files both internally and externally. $$anonymous$$ight be a bug if it isn't set?

A quick Google search seems to suggest that returning NULL for a public data path is a permissions thing, and there seems to be a few articles out there on how to edit the manifests to add/remove permissions for Android builds.

avatar image infosekr · Sep 05, 2015 at 01:25 AM 0
Share

Sounds like the best approach is to avoid Application.persistantDataPath, and write a Java plugin to get the Internal storage directory directly from the OS. Seems that the persistantDataPath can change based on if you have an SD card inserted or a USB cable plugged in anyway, not to mention why it returns null or String.Empty for some users in particular situations.

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Wiki

Answer by paulojorgemaiapereira · Aug 11, 2015 at 03:43 PM

On my case Application.persistentDataPath was returning a empty string. The problem was on the device. I restart the device and the Application.persistentDataPath start working fine again.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by sandolkakos · Aug 21, 2018 at 01:43 PM

My problem was solved when I noticed the carriage return (/r) character in the ProductName of my project. Look here: https://forum.unity.com/threads/app...-string-on-some-machines.384000/#post-3604512

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can multiple projects access the same Application.PersitanceDataPath? 0 Answers

[Android - Data save issues] Does the 'install location' determine the location of persistentDataPath? 1 Answer

[Unity5.6 && Android] Application.persistentDataPath return always "external" storage regardless "write access" settings? 0 Answers

Android writing to Application.persistentDataPath 4 Answers

Android Persistent Data loading fails 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges