Hello! I’ve been back and forth with this for quite a while now, and unfortunately have never been able to get this working properly.
I’m trying to create a usable Text Mesh Pro font asset from a Sprite Sheet bitmap image, and keep that font aligned to a “pixel grid” for display.
Here is the sprite sheet I started with:
Here are all of the steps I went through:
Scene Setup
-
Create a new scene
-
Add PixelPerfectCamera to the Main Camera.
-
Assets per PPU: 1
-
Reference Resolution: 160 x 144
-
Create a TMP Text Asset (UI → Text - Text Mesh Pro)
-
Change the Canvas Settings to the following:
-
World Space
-
Canvas Scaler Dynamic/Reference PPU: 1
-
Canvas Position: (0,0,0)
-
Canvas Width and Height: 160 x 144
-
The TMP Text Asset may need to have its position adjusted as well.
Font Creation
-
Import Font Sprite Sheet Image
-
Sprite Mode: Single
-
PPU: 1
-
Filter: Point
-
Compression: None
-
Create a Font Asset (Window → Text Mesh Pro → Font Asset Creator)
-
Source Font File: LiberationSans
-
Character Set: Custom Characters using the string in the Font Sprite Sheet (In my case, “0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ”)
-
Generate Font Atlas and Save
-
Under Font Asset, set all values under Face Info to Zero except:
-
Scale: 1
-
Line Height: 8
-
Ascent Line: 8
-
Click Arrow beside Font Asset and view the Material
-
Change Material type to “Bitmap Custom Atlas”
-
Under Material’s “Debug Settings,” set Font Atlas to Font Sprite Sheet
-
Go to Font Asset
-
Click 3 dots beside lock in the Inspector, and select “Debug”
-
Under “Atlas Textures,” under Element Zero, change reference to Font Sprite Sheet
-
Under “Atlas,” select Font Sprite Sheet
-
Under Atlas Width and Height, enter Sprite Sheet Width and Height (in our case, 104x24)
-
Click 3 dots again, and return to “Normal”
-
Go to Unicode # of Glyph (I started with 0030, “0”.)
-
Input the Bounding Box of the Glyph
-
Glyph Bounding boxes start from the bottom left corner
-
[X,Y] is the starting position on the sprite sheet; [W,H] is the width and height of the box on the sprite sheet
-
[W,H] is the World Width and Height
-
I don’t know what [BX] does but it only works when set to Zero.
-
[BY] should be character size (8 in our case)
-
[AD] is how far the to step forward after a character is drawn (8 in our case)
This means my first glyph had the following settings:
But this gave me the following results:
As you can see, this is mostly off the grid, but my 8x8 characters are slightly out of scale. By using my scaler image, I can see that the characters are around 10 pixels tall. The characters also seem to be positioned slightly off the screen, rather than directly in the corner as I’d expect. It seems like an extra line or two of pixels are getting attached to the glyph, but I don’t know why.
What steps have I performed incorrectly in my workflow above? I’ve attached my package to this post so that you can see all of my settings in action.