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
0
Question by bariscigal · Feb 05, 2015 at 03:12 PM · iospersistentdatapath

Application.persistentDataPath not working on ios but working on Mac Editor and Android

Hello , I am working on ios 8 and Unity 4.6.2f1 Pro

This piece of code is working on Android flawlessly. I am writing a texture from another method and reading it here. But on ios this doesn't seem to work. After this output :

Started Loading image from : /var/mobile/Containers/Data/Application/XXXXXXX-XXXXX-XXXX-XXXX-XXXXX/Documents/Portrait/playerPortrait2.jpg

It gets stuck on the while loop waiting for the www request endlessly.

         string portraitPath = Path.Combine(Application.persistentDataPath,"Portrait");
         string PlayerPortraitImageBigPth = Path.Combine(portraitPath,"playerPortrait.jpg");

         WWW fileReq = new WWW("file://" + PlayerPortraitImageBigPth);
 
         playerPortraitBig = new Texture2D(400,400);
 
         if(File.Exists(PlayerPortraitImageBigPth))
         {
 
             Texture2D image = new Texture2D(400,400);
 
             Debug.Log ("Started Loading image from : " + PlayerPortraitImageBigPth);
             while(!fileReq.isDone)
             {
                 //IT GETS STUCK HERE WHILE WWW LOADING
             }
             Debug.Log ("Done Loading image from : " + PlayerPortraitImageBigPth);
             if(fileReq.isDone){
                 fileReq.LoadImageIntoTexture(image);
                 playerPortraitBig = image;
             }
             else{
                 Debug.Log ("File read failed. the path looked : " + PlayerPortraitImageBigPth);
                 playerPortraitBig = null;
             }
         }
         else{
             Debug.Log ("Folder failed. the path looked : " + PlayerPortraitImageBigPth);
             playerPortraitBig = null;
         }

Any help would be great. BTW i have tried file:// and file:/// with no success. also tried hardcoding the file path directly like :

Application.persistentDataPath + "/Portrait/playerPortrait2.jpg";

Comment
Add comment · Show 4
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 Graham-Dunnett ♦♦ · Feb 05, 2015 at 03:38 PM 1
Share

I suspect your while loop is eating all the CPU time.

avatar image bariscigal · Feb 05, 2015 at 03:41 PM 0
Share

I would love to check that option. Will think of a way. But a really cheap android tablet is working in this matter? (www.bountyhunt.net this is the game and the android version has this on the multiplayer screen. You can take a photo and use it as your avatar in the game. )

avatar image Bonfire-Boy · Feb 05, 2015 at 04:03 PM 2
Share

First thing is, you start your WWW file-loading request and THEN check if the file exists. Surely that should be the other way round?

Secondly, I think Graham's right. What you're doing is testing if fileReq has returned an error 'while' you know that it hasn't finished yet. Let it finish, then see if there's an error.

To do this, try putting the file loading into a coroutine. After constructing the WWW object you'd have

yield return fileReq;

and only after that do you have the code to test & process the response to the WWW request.

avatar image bariscigal · Feb 05, 2015 at 08:14 PM 0
Share

That was right. I haven't made it a coroutine in the first place because i wanted it to be a static method. But i made it a coroutine now and it works. I would be glad if you can write your comments as answer and i can select it as answered. Thank you very much. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by bariscigal · Feb 06, 2015 at 01:23 PM

Ok as #Bonfire Boy and #Graham Dunnett pointed out it was a problem of cpu load and bad coding (my bad) Here is the working solution. All credits goes to names mentioned

 IEnumerator LoadImageFromPath(){
         portraitDirectory = Path.Combine(Application.persistentDataPath,"Portrait");
         PlayerPortraitImage = Path.Combine(portraitDirectory,"playerPortrait.jpg");
         playerPortraitBig = new Texture2D(400,400);
         
         if(File.Exists(PlayerPortraitImage))
         {
             yield return StartCoroutine(RequestImage());
             
             if(fileReq.bytes.Length > 0){
                 Debug.Log ("Done Loading image from : " + PlayerPortraitImage);
                 fileReq.LoadImageIntoTexture(playerPortraitBig);
                 //do anything with the acquired image as texture
             }
             else{
                 Debug.Log ("File read failed. the path looked : " + PlayerPortraitImage);
                 GeneralTools.playerPortraitBig = null;
             }
         }
         else{
             Debug.Log ("Folder failed. the path looked : " + PlayerPortraitImage);
             GeneralTools.playerPortraitBig = null;
         }
     }
     
     IEnumerator RequestImage(){
         Debug.Log ("Started Loading image from : " + PlayerPortraitImage);
         fileReq = new WWW("file://" + PlayerPortraitImage);
         while(!fileReq.isDone){
             yield return null;
         }
         yield break;
     }
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

20 People are following this question.

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

Related Questions

file saved to iOS persistent directory exists during session but is gone next session 0 Answers

How do you create a subfolder inside persistentDataPath in iOS? 0 Answers

How to download asset bundles and storing it locally in ios 0 Answers

persistentDataPath not working on iOS. UNITY 4.PRO. 3 Answers

Delete screenshots from Gallery 0 Answers


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