xnb files from spritefont "Could not load font asset as a non-content file!"!


I’m trying to add a font to my game but recently it doesn’t work. I’ve added fonts before so I know the whole process of add to pipeline -> create xnb file -> in visual studio set Build Action to “Content” and “Copy always”. My texture files works flawlessly doing this method so I don’t know why the spritefont won’t work.

Anyone got any clue?

What platform are you running on? If it’s not Windows, upper and lower-case of the filename matters.

I’m developing on both iOS and Windows, DesktopGL. Both the folder and filename is lower-case so that should not be the problem.

If the texture in the sprite font is compressed, it will fail on one platform because Windows supports DXT compression and iOS supports PVR compression. One sprite font file cannot support both platforms unless the texture is not compressed.

So what do you suggest me to do if I may ask? Can I have a font w/o being compressed? I have made it work before but I dont know what I did

I believe it is a property in the SpriteFontProcessor in the content builder to set the texture to compressed or not.

I changed the texture format to “NoChange”, however I still get the non-content file error :confused:

There’s something else we’re missing then. Is the file in the project output directory in the correct place?

I think it is in the correct place… https://gyazo.com/7634fb4d3156d5da83f7d7e464918087 this is my CONTENT folder, as you can see the arial.xnb (which is the font) exist in the output. This is also how all my images looks.

Is your ContentManager set to use “Content” as the RootDirectory? If so (this is the default), those files need to be in a Content subfolder.

RootDirectory is indeed set to “Content”, while Content/bin/DesktopGL/ is my output folder. Tried to load “bin/DesktopGL/arial” but same result.

The xnb files need to go into a Content folder in your VS project. They will then be copied to a Content folder in your VS project output.

If I understand it correctly the xnb files should already be in the content folder.

  1. I create spritefont in the pipeline tool and rebuild -> https://i.gyazo.com/ec207f05f5316208bd64d899736c4b42.png

  2. I then later add the file in the Content folder in VS from the output folder (which is a sub folder of Content) and set Build Action to “Content” and to “Copy always”.

Is there anything I’m missing?

That should work… You can set the build action of the Content.mgcb to MonoGameContentReference, that way it automatically builds (if necessary) and copies the result to your output folder when you build the project. That build action should be available if you started with a template.

You can make sure the content is in the right place by checking the output folder of your project (under Properties > Build) and check that folder to see if it has Content/font.xnb file .
(e.g. C:/User/Projects/MySolution/MyProject/bin/Windows/x86/Debug/Content/font.xnb).
That is where it should be so you can load it. After that you should just be able to load it using Content.Load(“font”) if Content.RootDirectory is set to “Content”.