Search Unity

TextMesh Pro Sprite asset from asset bundle?

Discussion in 'UGUI & TextMesh Pro' started by shpkng, Dec 15, 2019.

  1. shpkng

    shpkng

    Joined:
    Apr 15, 2019
    Posts:
    7
    Hi guys, I'm trying to use tmp's richtext to build panels with sprites and texts in lines. But tmp seems to be not able to load sprites from asset bundles and sprite atlases, is there a work-around or better solution?
    I'm trying to build a item detail panel which has up to 30 lines, which individually has a sprite and two blocks of text.
     
  2. MohawkTesting

    MohawkTesting

    Joined:
    Apr 17, 2018
    Posts:
    2
    I ran into the same issue not too long ago. It seems like TMP only references spriteassets from the Resources folder. The workaround I found was to load the TMP_SpriteAsset from the asset bundle and add it to the fallbackSpriteAssets list of the TMP_Settings.defaultSpriteAsset. Then when using the sprite tag in your text, you use the default sheet (i.e. just use the sprite name, don't include the sheet name). like so: <sprite name="my-icon"/>. When you unload your bundle be sure to remove the asset from the fallbacks
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You are correct that TMP expects resources that may be referenced via rich text tags to be located in a Resources folder at the locations specified in the TMP Settings which for Sprite Assets is "Resources/Sprite Assets".

    Assigning the newly Sprite Asset as a general fallback will work as well as assigning it as a fallback to the default sprite asset.

    You can also assign a Local Sprite Asset to individual text objects.

    The following delegate was also added in the latest release versions of TMP

    /// <summary>
    /// Event delegate to allow custom loading of TMP_SpriteAsset when using the <sprite="Sprite Asset Name"> tag.
    /// </summary>
    public static event Func<int, string, TMP_SpriteAsset> OnSpriteAssetRequest;

    So whenever a sprite asset is referenced via rich text, the following delegate will be called thus giving you the opportunity to provide one.
     
  4. kexhong000

    kexhong000

    Joined:
    Jul 13, 2020
    Posts:
    2
    I have multiple SpriteAsset which need to be added to TMP_Settings.defaultSpriteAsset.fallbackSpriteAssets.(Load From AssetBundle)
    How to use the tag <sprite="EmojiDynamic" anim="0,8,10">?
    Or,<sprite name="EmojiDynamic" index=1>?
    The multiple SpriteAssets need to be loaded From AssetBundle while game run, but do not place to Resource.