Top BMFont Alternatives and When to Use Them


What is BMFont?

BMFont is a bitmap font generator that takes TrueType or OpenType font files and exports:

  • A texture atlas containing glyph bitmaps.
  • A text-based descriptor (commonly .fnt) describing glyph positions, sizes, kerning, and other metrics. This combination lets you render text by sampling pre-rendered glyph images rather than using vector-based system fonts.

Why use BMFont with Unity?

  • Performance: Bitmap fonts avoid runtime rasterization cost and can be faster on some platforms (especially older / low-power devices).
  • Visual consistency: Guarantees identical pixel output across devices and resolutions when used with pixel-art or stylized fonts.
  • Special effects: Easier to apply pixel-perfect outlines, gradients, or shader effects per-glyph.
  • Legacy compatibility: Useful when porting older games that rely on bitmap-font atlases.

Step 1 — Generate BMFont files

  1. Download and open AngelCode BMFont (Windows) or use an alternative bitmap-font generator that outputs the AngelCode .fnt format (some cross-platform tools and command-line utilities also exist).
  2. Load your TTF/OTF font.
  3. Configure export settings:
    • Font size: choose the pixel size that matches your target resolution and in-game scale.
    • Padding and spacing: set internal padding to avoid glyph bleeding when sampling the atlas.
    • Texture size and format: choose power-of-two sizes (e.g., 512, 1024) if you plan to use certain compression or mipmaps in Unity; consider multiple pages if all glyphs don’t fit in one atlas.
    • Character set: include only characters you need (ASCII, extended Latin, Cyrillic, custom glyphs) to reduce atlas size.
  4. Export:
    • Choose “Export options” to create a .fnt file in either text (common) or XML format and a PNG (or other) texture atlas (often named .png and .fnt with matching base names).
    • If BMFont produces multiple pages, it will output multiple texture files and the .fnt will reference them.

Notes:

  • For pixel-art fonts, enable “monochrome” or render at exact pixel sizes to avoid anti-aliasing blur.
  • If you need signed distance fields (SDF) for high-quality scaling, you’ll need a different workflow or SDF generator; BMFont itself can do distance field output via plugins or external tools.

Step 2 — Prepare files for Unity

  1. Create a folder in your Unity project’s Assets (e.g., Assets/Fonts/BMFont).
  2. Copy the .fnt file and all generated PNG pages into that folder.
  3. In Unity, select each PNG and set import settings:
    • Texture Type: Texture (or Default).
    • Texture Shape: 2D.
    • Wrap Mode: Clamp (or Repeat if tiling).
    • Filter Mode: Point for pixel-perfect, Bilinear/Trilinear for smooth fonts.
    • Max Size: ensure large enough to hold the atlas at runtime.
    • Compression: None for pixel-perfect fonts; select a compressed format (e.g., ASTC/DXT) if you need memory savings but test quality.
    • Generate Mip Maps: enable if you plan to scale down and use bilinear/trilinear filtering; disable for strict pixel-art.
  4. Apply changes.

Step 3 — Import the BMFont descriptor

Unity doesn’t natively import .fnt files as a single “BMFont asset,” but you can use several approaches:

Option A — Use a ready-made BMFont importer plugin

  • There are community plugins (free and paid) on the Unity Asset Store or GitHub that parse AngelCode .fnt files and create Unity Font assets or custom mesh-based text renderers.
  • Install a plugin, then use its import command to generate a Unity Font or a custom bitmap-font asset tied to the texture pages.

Option B — Create a dynamic Unity Font (less common)

  • Manually create a Unity Font asset and assign a Material/texture. This workflow is limited because Unity’s built-in Font expects font texture in a specific format and often requires an accompanying character info array. Most devs prefer a plugin or custom script to parse .fnt and populate a Font asset.

Option C — Use TextMeshPro (recommended for modern Unity projects)

  • TextMeshPro supports bitmap font import and is the recommended text system in Unity for quality and features.
  • Steps for TextMeshPro:
    1. Install TextMeshPro (if not present) via Window > Package Manager or Import TMP Essentials.
    2. In the Project window, right-click the .fnt file (or open TMP’s Font Asset Creator). If you installed a BMFont importer for TMP, use it. Alternatively:
      • Open TextMeshPro > Font Asset Creator (Window > TextMeshPro > Font Asset Creator).
      • TMP expects a source font or a texture atlas + glyph data. Some community tools convert AngelCode .fnt + PNG pages into a TMP Font Asset directly.
    3. If using a converter/importer, run it to generate a TMP Font Asset and assign the atlas textures.
    4. The resulting TMP Font Asset includes face metrics, glyph rects, kerning, and a material.

If you prefer not to use plugins, you can write a simple .fnt parser (C#) to create a TMP Font Asset at runtime or in editor scripts by reading the .fnt, creating glyph tables, and assigning the atlas texture(s). This requires familiarity with TMP’s FontAsset APIs.


Step 4 — Create materials and assign shaders

  • For legacy Unity Font assets or custom mesh renderers, create a Material that uses the appropriate shader (Sprites/Default or UI/Default).
  • For TextMeshPro, the import process usually creates a Material for the TMP Font Asset. Open the material and pick a shader from the TextMeshPro shaders (Distance Field or Mobile shaders) depending on whether you used regular bitmap or SDF workflow.
  • Configure the material’s texture to the atlas and set tint, outline, or glow properties as needed.

Step 5 — Using the font in scenes

A. UI (Unity UI / Canvas)

  • For Unity UI Text:
    • If you created a Unity Font asset, assign it to a Text component.
    • For best results and modern features, use TextMeshPro UGUI components and assign the TMP Font Asset created from BMFont.
  • Adjust font size, line spacing, and alignment. For pixel fonts, use whole-number scale values and set Text component’s RectTransform to match pixel grid.

B. World-space / 3D text

  • Use TextMeshPro TextMesh components and assign the TMP Font Asset.
  • Position in world space, and scale carefully to maintain pixel fidelity if desired.

C. In-game scripts

  • Access and modify text via typical APIs:
    • UnityEngine.UI.Text.text = “Hello”;
    • TMPro.TMP_Text.text = “Hello”;

Tips for best results

  • Kerning: Ensure your .fnt export includes kerning data. TextMeshPro and good importers will import kerning pairs; otherwise spacing may look off.
  • Multiple texture pages: Confirm your importer/plugin supports multi-page atlases and the material references the correct texture page for each glyph.
  • Pixel-perfect UI: Use Point filter mode, no mipmaps, integer positions, and match atlas size to runtime scale.
  • Scaling: For large scaling ranges, consider SDF fonts (TextMeshPro supports SDF generation) instead of bitmap atlases; SDF gives crisp scaling and outline control.
  • Localization: Include only necessary glyph ranges or create separate atlases per language to save memory.
  • Atlas padding: Use at least 1–2 pixel padding around glyphs to avoid edge artifacts when using bilinear filtering or mipmaps.
  • Test on target platforms and device resolutions.

  1. Generate BMFont .fnt + PNG(s) at the pixel size you want.
  2. Copy files into Assets/Fonts/BMFont.
  3. Use a BMFont-to-TextMeshPro importer (or write an editor script) to produce a TMP Font Asset and Material.
  4. Assign the TMP Font Asset to UI or TextMesh components.
  5. Adjust material and component settings for pixel-perfect display or smooth scaling.

Troubleshooting common issues

  • Missing glyphs: Re-export .fnt including desired characters or add them to the character set.
  • Blurry text: Check texture import filter mode, mipmaps, and canvas scaling; use Point filtering for pixel fonts.
  • Incorrect spacing: Confirm kerning and spacing exported and imported correctly; inspect .fnt values and importer behavior.
  • Atlas bleeding: Increase padding or disable bilinear filtering; use clamp wrap mode if appropriate.
  • Multi-page errors: Ensure the importer supports multi-page .fnt or merge pages into a single atlas before importing.

Advanced: Writing a simple .fnt importer for TMP (outline)

  • Read the .fnt text file format (key/value pairs per line; pages, chars, kernings).
  • Load atlas PNG(s) as Texture2D assets.
  • Create a TMPro.TMP_SpriteAsset or TMP Font Asset and populate glyph tables, glyph rects (x, y, width, height), metrics (xoffset, yoffset, xadvance), and kerning pairs.
  • Use AssetDatabase APIs to create and save the TMP Font Asset as an Editor script.

Using BMFont with Unity gives you precise control over how text appears and performs, especially for pixel-art or highly stylized projects. For modern Unity projects, convert BMFont output into a TextMeshPro Font Asset for the best combination of quality, features, and ease of use.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *