Error: couldn't find a default importer for .tff files

Restart didn’t help.
It is the entire Spritefont file.
Tried. Didn’t work

You need to add the .tff file to the same folder as the .spritefont. It needs to have the exact same file name as what shows up when you view the font in C:\Windows\Fonts. For example, I was using a font whose file name was lane narrow.tff but in fonts it showed up as Lane. Adding the file as Lane.tff to the content folder resolved the problem.

2 Likes

Strange…

I was about to ask what is the font’s name in notepad… :sake:

@Synammon is right, you need to write the filename exactly

It is the entire Spritefont file.

Your file is missing important tags in it if that is the case. The formatting looks like it got messed up so I suspect something got removed and that is in fact actually not your file. Just to be clear, the file you posted should be wrapped in two xml tags like this

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="Graphics:FontDescription">
      .... Inside here is what is supposed to be what you posted ....
  </Asset>
</XnaContent>

If that is not the case you need to correct your xml

1 Like

I already posted the complete code above in case anyone needs it…

This is a few months old, so you may have already fixed the issue yourself by now, but I ran into the same thing and found a fix:

The issue is that the MGCB Content Editor is trying to import the .ttf file itself as a resource, which isn’t something it knows how to do. While the .ttf file needs to be in the same folder as the .spritefont object in the filesystem, the .ttf file doesn’t need to exist in the Content.mgcb file at all. If you right-click the .ttf file in the content editor and click “Exclude from project”, it’ll stop trying to import the file directly, instead learning about it from the .spritefont file’s specification when the project loads. Once I did so, the errors disappeared and I was able to use the font in the game.

7 Likes

Thank you! This was helpful.

I was pretty fed up with none of the replies working for me, so I solved it by trying different things.

Specs to start with:
Windows 11,
MGCB Editor version 3.8.1.303,
Microsoft Visual Studio Community 2022 (64-bit) Version 17.6.5,
.NET 4.8.09037.

I also installed the font by double-clicking the .ttf file but that didn’t do much, but might help someone else.

The content manager for MonoGame does not like it when you edit the files outside of the content manager. So I would suggest just removing the font folder both from the content manager and the file system in that order for a clean start if you have not done so already.

  1. Create a folder called “Fonts” on your desktop or anywhere other than in the project folder.
  2. Download a font of your choice that has a .ttf extension (this will work for all fonts by Damien Guard) and put it in the “Fonts” folder.
  3. Open the content manager, create a .spitefont file, and copy it into the “Fonts” folder.
  4. Close the content manager and don’t save anything.
  5. Open the .spitefont file in a text editor and change the FontName attribute to whatever font you selected, make sure it is the same name (case sensitive) as the .ttf file, for example <FontName>Hourglass</FontName>.
  6. Save the .spritefont file with the correct name, for example, Hourglass.spritefont.
  7. The “Fonts” folder should now contain 2 files, Hourglass.ttf and Hourglass.spritefont.
  8. Open the content manager, create a folder called “Fonts”, Right-click the “Fonts” folder, Add->Existing Folder, find and select the Fonts folder with the .spritefont and .ttf file and use “Copy the file to the directory”.
  9. Here is the most crucial part, go to the content manager and select the .spirtfont file, under “Properties”, set it to:
  • Settings/Build Action = Build
  • Settings/Importer = Sprite Font Importer - MonoGame
  • Settings/Processor = Sprite Font Description - MonoGame
  • Processor Paramters/PrematurlyAlpha = True
  • Processor Paramters/TextureFormat = Compressed
  1. Select the .ttf file and set the properties to:
  • Settings/Build Action = Copy
  • Settings/Importer = (wont matter)
  • Settings/Processor = (wont matter)
  1. Save and exit the content manager.

For a one-liner test, you can type the following in the draw method (only for testing, code it properly when it works):
_spriteBatch.DrawString(Content.Load<SpriteFont>("Fonts/Hourglass"), "MonoGame Font Test", new Vector2(100, 100), Color.White);

After you have gotten this to work, it should be a lot easier to modify the .spritefont file and experiment!

2 Likes

In windows 11, double clicking a ttf font to install it will only install if for the current user.

You need to install the font as a global font in windows for the MGCB to pick it up properly if you dont want to use the ttf file directly.

To do this hold down shift (might be ctrl) and right-click the ttf file and select Install for All Users. This installs it to the global fonts section so that the.MGCB can pick it up properly

There is usually a checkbox to install for all users too.

EDIT

Just checked and it is only visible in the right click menu when you click show more options…

1 Like

Ah right, forgot about Windows 11 changing the context menu to have the Show More now.

What did it for me was: Select the .ttf file (MGCB Editor - Content importer) and set the properties to:

  • Settings/Build Action = Copy

It’s worth mentioning I don’t not use the SpriteFont, I load the .ttf file from code, because I use FontStashSharp. (Via. MLEM UI, but doesn’t matter here)
First I loaded the file like this:

File.ReadAllBytes(@"Fonts/DroidSans.ttf")

But this does not work on Android. Instead, MonoGame has this build-in method that is cross platform:

TitleContainer.OpenStream(@"Content/Fonts/YourFont.ttf")

You cannot add .ttf files with the MGCB Editor, unless you set:

Build Action = Copy

1 Like