Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 destro22 · Mar 01, 2020 at 10:15 PM · androidwebrequeststreamingassetspersistentdatapathfilepath

Why am I unable to locate font files(.ttf) in unity android game in persistentDataPath?

Can somebody guide me in the right direction? My android game that I made on unity 2018.4.9 using C# on VS 2017 is unable to detect files at persistent data path.

The two font files are located in the persistent data path directory alt text

This is my code which locates the two font files.

  string fontpath1 = Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";
     string fontpath2 = Application.streamingAssetsPath + "/LEOPALMHINDI14K240.TTF";
     //Check Font 1 existence
     if (File.Exists(fontpath1))
     {
         Debugtext.text += "true1\r\n";
     }
     else if (!File.Exists(fontpath1))
     {
 
         Debugtext.text += "false1\r\n";
 
 
     }
 
     //Check Font 2 existence
     if (File.Exists(fontpath2))
     {
         Debugtext.text += "true2\r\n";
     }
     else if (!File.Exists(fontpath2))
     {
 
         Debugtext.text += "false2\r\n";
 
 
     }
     //Third File(Image file existence)
     if (File.Exists(Application.persistentDataPath + "/FullShot.jpg"))
     {
         Debugtext.text += "trueIM\r\n";
     }
     else if (!File.Exists(Application.persistentDataPath + "/FullShot.jpg"))
     {
 
         Debugtext.text += "falseIM\r\n";
 
 
     }
     Debugtext.text += Application.persistentDataPath;

Debugtext.text is a textbox which shows the result of three files: a) Font File 1 b) Font File 2 c) An Image File

The debug traces for files 1 and 2 are always false, whereas the image file returns true when it's present.

These fonts files are downloaded using UnityWebRequest from streaming path to persistent path using the following code:

 string fontpath1 = Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";
     string fontpath2 = Application.streamingAssetsPath + "/LEOPALMHINDI14K240.TTF";
 
     //Request Font1
 
     UnityWebRequest request = UnityWebRequest.Get(fontpath1);
     request.SendWebRequest();
     while (!request.isDone)
     {
 
 
     }
     System.IO.File.WriteAllBytes(Application.persistentDataPath + "/LEOPALMHINDI15K710.TTF", request.downloadHandler.data);
 
     //Request Font2
 
     UnityWebRequest font2 = UnityWebRequest.Get(fontpath2);
     font2.SendWebRequest();
     while (!font2.isDone)
     {
 
 
     }
     System.IO.File.WriteAllBytes(Application.persistentDataPath + "/LEOPALMHINDI14K240.TTF", font2.downloadHandler.data);

The files are downloaded and written properly to the Persistent data path which is storage/emulated/0/Android/data/com.appname.com/files(cross-checked in traces.)

Why are these two font files not being located and returning false while other files in same path returns true?

Please, anyone, help me fix it. I gotta locate these two font files.

whatsapp-image-2020-03-02-at-030144.jpeg (66.4 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kaziata · Mar 02, 2020 at 04:53 AM

@destro22

It looks like you are using two different methods to find these files. Have you tried:

Application.persistentDataPath +"/LEOPALMHINDI15K710.TTF";

Instead of: Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";

Comment
Add comment · Show 1 · 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 Bunny83 · Mar 02, 2020 at 05:18 AM 0
Share

Right. The code checking the existance of the files still uses the Strea$$anonymous$$gAssetsPath which of course won't work.


ps: Like always I'd like to mention that I would highly recommend to use System.IO Path.Combine(Application.strea$$anonymous$$gAssetsPath, "LEOPAL$$anonymous$$HINDI15$$anonymous$$710.TTF") to combine several path fragments. Note that I removed the slash from the string constant. The Combine method ensures that the right slash is used depending on the platform. Also it handles potential trailing slashes in the strea$$anonymous$$gAssetsPath / persistentDataPath correctly.

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

262 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image

Related Questions

Getting Localization data in Android with streamingAssets and UnityWebRequest 0 Answers

Where to store files in Android that can be accessed later via path? 1 Answer

Loading an image from streamingassets fails every time on Android 1 Answer

Get Contents of Folder Using UnityWebRequest 0 Answers

Fatal Exception when loading multiple image files on Android from persistent data path 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