Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Is it possible to add a sprite generated at runtime to TMP text (e.g. a controller glyph)?

Discussion in 'UGUI & TextMesh Pro' started by dtootill, Feb 13, 2024.

  1. dtootill

    dtootill

    Joined:
    Oct 9, 2020
    Posts:
    29
    Is there any way to include a runtime-generated sprite in TMP text? TMP supports sprites in messages with <sprite index=x> references to a sprite sheet associated with the text field. However, this requires a sprite sheet known at compile time. Is it possible to insert a sprite created at runtime into a text field?

    For background, I'm adding support for controllers to my game, and one part of this is inserting controller button glyphs into messages (so that the player can easily tell which buttons do what). The game uses Steam Input, a feature of Steam that allows players to customize controller actions (meaning that the game must be prepared for an action to be associated with any button on any controller). The Steam Input API supports this by providing a way to obtain a graphic for the glyph of the button currently associated with an action. It's straightforward to convert the returned glyph to a sprite. Is there any way to insert this sprite into a TMP string?