Icons, Images and Buttons Inside Unity Text
Last reviewed
Short answer
Icons inside a sentence, such as a coin before a price or a controller button in a tutorial, are drawn in TextMesh Pro through sprite assets packed from a sprite sheet. Anything that is not a sprite, like a live UI element or a 3D object, has to be positioned over the text by hand.
UniText places both sprites and objects in the text flow: <sprite=name> draws a sprite and <obj=name> places a prefab or a scene object, each laid out as a character, so it wraps, aligns to the baseline and moves with the line.
The usual options
- TextMesh Pro sprite assets. Icons are sliced from an atlas texture into a sprite asset and placed with
<sprite name="…">, with per-sprite offset, advance and scale and optional tinting. Each sprite asset holds one texture; more sheets are reached through fallback sprite assets, and Unity advises one atlas per object because each extra atlas adds a draw call. - Objects over the text. None of TextMesh Pro's rich-text tags embeds a GameObject. The usual workaround reserves space with a tag, reads character positions from the text info and moves separate objects there, updating them whenever the text changes or reflows.
- UI Toolkit. Uses the same sprite asset model and has no tag for inline elements. Unity has said it plans to let text embed visual elements.
How UniText places media in text
- One character each. Every
<sprite>or<obj>inserts a single object-replacement character, so advance, line breaking, baseline alignment and every text index treat it as a character. - Sprites from anywhere. Sprites come from a list on the modifier or a shared project asset, by name, with no sprite sheet to pack.
- Objects, not just images.
<obj>clones a UI prefab or positions an existing scene object, such as a button, an animated icon or a progress bar, and keeps it in place as the text reflows. Removing the tag restores the object's position. - Per-use adjustments. Size, offset, advance, line height above and below, pivot and rotation are set in em units in the tag, per entry or per key, and sprites can keep their own colors or take the text color.
- Clickable. Inline media can be part of an interactive range, so an icon inside a link is clicked together with its text.
- In any script. Media follow the text's direction, so an icon in an Arabic sentence lands where the right-to-left layout puts it.
text
Press <sprite=gamepad_a> to jump, collect 50 <sprite=coin,i> and open <obj=chest_button>.Here i tints the coin with the text color, and chest_button is a UI prefab cloned into the line.
Questions
Do I need to pack my icons into a sprite sheet?
No. Sprites are referenced by name from a list or an asset; how they are stored in textures is up to the project.
Can an inline object be interactive?
Yes. A cloned prefab or a scene object keeps its own components, so an inline button is a real button.
Check it in your project
Run the browser demo, follow the setup guide, or compare the free version with the licenses.
Related problems
- Clickable Links in Unity Text: Hover, Click and URLsTextMesh Pro marks links but leaves hit-testing and styling to your code. UniText makes link tags, Markdown links and bare URLs clickable with hover states and events on canvas and world-space text.
- Markdown in Unity Text: Bold, Links and Lists Without ConversionTextMesh Pro and UI Toolkit show Markdown as raw asterisks. UniText reads inline Markdown directly, including bold, italic, links, lists and code spans, and copies formatted text as Markdown or HTML.
- Crisp Pixel Fonts in Unity: No Blur, Effects in Whole PixelsPixel fonts blur in Unity when rendered from distance fields, filtered or placed off the grid. UniText detects pixel fonts and renders them texel-exact, with strokes, shadows and animation in whole pixels.
