Jump to content

How to get Unity to load a TTF font file? It refuses to do it.


Recommended Posts

Every documentation I can find on Unity seems to imply that if I wanted to load a font, I can do it by putting that font file into the Resources folder, and then running code along these lines:


Font lblFont = (Font)Resources.Load( "LiberationMono-Regular.ttf", typeof(Font) );
Debug.Log( "lblFont is " + (lblFont == null ? "null" : "not null") );

But every time I try that, I get "lblFont is null". I've tried with the .ttf on the filename. I've tried without the .ttf on the filename. I've tried with different font files. It just will not load the font at all, and this is an area where Unity won't throw exceptions - just return null without explaining itself as to what the problem is.

So what am I missing here? What am I doing wrong?

(I'd like to be able to have a resources folder in the mod's gamedata area, but that's a second problem I haven't gotten to yet. It won't even load it from the KSP_Data/Resources .)

Update: I have tried putting the font file in both of these locations:

$KSP_HOME/Resources

$KSP_HOME/KSP_Data/Resources

And I have tried loading it using both the name with the .ttf extension and the name without it.

None of that worked.

Edited by Steven Mading
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...