0

I am generating (or at least attempting to) a TMP_SpriteAsset at run time, and adding this to the list of fallbacks on the default SpriteAsset.

It is not possible to build the SpriteSheet at compile time, it has to be dynamic for this project.

To do this I am creating an empty TMP_SpriteAsset, along with empty texture and placing the sprites into the sheet as required. I am creating a TMP_SpriteGlyph setting the properties, and then creating a TMP_SpriteCharacter with the unicode 0xFFFE and the glyph created previously.

Assigning a name to the character after it is created.

I then add the Character and then Glyph to spriteCharacterTable and spriteGlyphTable.

If at this point I attempt to use the sprites, they appear in the inspector and all values are correct as well as their bitmaps, co-ordinates and names, but TMPro cannot find them by name, and renders the unknown sprite question mark.

OK, so I call UpdateLookupTables() on my Sprite Asset after adding them, which is mentioned in the docs, however now, the text is only rendered up to the first sprite! at which point it stops, no text or sprites rendered after this point, nothing in the Log or Error log. It just stops!

Inspecting the SpriteAsset and the glyphs and characters are all there as before!

I assume I am missing some key somewhere, anyone able to help?

Unity: 2019.4.26 TMPro: 2.1.4

Graeme
  • 1,643
  • 15
  • 27
  • I have noticed if I mangle the name of a sprite so it doesn't match those in the table, then it will again render the missing sprite image, It still will not render past one it finds, it will however render from from en existing SpriteAsset, but only if it is before one of the dynamically added sprites. – Graeme Jan 05 '22 at 20:31

1 Answers1

0

In my case I had missed the metrics property of the Glyph!

I discovered this by reading through the private UpgradeSpriteAsset method of TMP_SpriteAsset.

I had created my glyph and only set the index, sprite, scale, and glyphRect properties, which will it seems allow it to appear in the inspector, but will cause it to not render, and even abort the rendering (I suspect no check the metrics property before trying to access somewhere in TMPro.

Graeme
  • 1,643
  • 15
  • 27