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

Duvyanshu

~matchmaker~
Joined
Feb 20, 2020
Messages
26
Programming Experience
1-3
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. This is a screenshot of app persistent data folder.

This is my code which locates the two font files.

C#:
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:

C#:
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.
 
So you are back to writing a "game" rather than an application. Why would a game need to download fonts and pictures dynamically instead of having it built into its Unity assets and distributed at installation time?

Whereas in your other thread I was just mildly suspicious, but felt like giving you the benefit of doubt, this time I'm all klaxons and alarm bells like @Sheepings was. Good luck with your "game".
 
Listen, mr @Skydiver ... I tried using unity assets but I think you are well aware that when packed as apk he location of files change that location and I need to get the path of the font files.
 
I
So you are back to writing a "game" rather than an application. Why would a game need to download fonts and pictures dynamically instead of having it built into its Unity assets and distributed at installation time?

Whereas in your other thread I was just mildly suspicious, but felt like giving you the benefit of doubt, this time I'm all klaxons and alarm bells like @Sheepings was. Good luck with your "game".
[/QUOTES
I am gonna be as humble as I can be. I cane to this forum with a lot of hope but seeing your plucky attitude instead of helping freelance developers you are always suspicious over them. Change your forum name from c# forum to suspiciousforum.
I posted it with the context of game because Last time i said it was an app you all went nuts. Why is retrieving my own font file would be so suspicious. Oh god, I cant do this again. You guys are over my head now.
 
@Skydiver i think you have heard of localisation? If you have, that is exactly what I am trying to do with local language font files but file.exist(fontpath) is not detectig the font in the persistent data path.
 
I fixed it. For anyone who wants to find it Simply use Unity Web Request to download fonts from streaming assets path to persistent data path(Don't forget to dispose the request). For Itext7 or above users to create localized pdf in android make sure you put i18n.dll and i18n.west.dll in your project or add their references in your project. Plenty of resources are available online about the latter for those who can look.
 
Last edited by a moderator:
@Duvyanshu please refrain from tagging me in topics where I have not yet replied. If I wanted to reply to your topic, I would have done so and in my own time. Please take note that all of the people on this website who participate on these forums; do so in their own free time and we are not all in the same countries. Which means we are all in different timezones. So please wait 12 hours before bumping your topics and asking if anyone is going to help you or not. You need to be patient when requesting help on the forums. You should also know that no one person is obliged to answer your questions, and they do so at their own accord.

To be clear; I don't have any intention of answering your questions regarding this project, because I don't wholeheartedly believe what you are telling us to be true regarding your projects purpose. And I certainly don't believe you have honest intentions regarding whatever it is you're building. Your very first topic set-off some warning signs for me, and when I questioned you about this product you are building, both I and Skydiver were met with umpteen counts of BS and obvious lies, which led me to not trust you or your intentions regarding your application. I told you before, and I am telling you again, I won't be replying to any of your future posts regarding this project.

If other people believe your intentions, then they are welcome to discourse with you however they like. I nor Skydiver will be one of those people. Lastly, if you do want further help in the future, It would be a good idea to tone down your posts when you're directing your frustrations at people by tagging them who haven't even replied to your topic yet, I would like to think that one of the Mods have already given you a warning regarding your tantrums, and attempts to patronise other members of the board.

I see that someone has been clearing up some of your more aggressive posts. Except they forgot to remove post 4 which you stated : I posted it with the context of game because Last time i said it was an app you all went nuts. A quick recap shows that you stated it was a game and then changed your mind mid-topic and said it was an app upon undergoing questioning.
I think you are well aware that when packed as apk he location of files change that location and I need to get the path of the font files.
No it doesn't. There is also no reason to download fonts when you should be setting the font in Unity itself. But sure lets park this one here too, and agree to part ways on this discussion.
 
Back
Top Bottom