Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro Is possible to insert animated sprites in TextMeshPro?

Discussion in 'UGUI & TextMesh Pro' started by Nanoflash, Nov 30, 2020.

  1. Nanoflash

    Nanoflash

    Joined:
    Dec 2, 2014
    Posts:
    7
    I know that there is a tag for inserting sprites <sprite ...> in TextMeshPro. I want to insert animated sprites....
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You can use the "anim" attribute with the <sprite> tag. See the following post for an example.



    The text used in this example is as follows: "Animated <sprite anim="0,8,30"> Sprites"

    anim="first index, last index, frame rate"
     
  3. Nanoflash

    Nanoflash

    Joined:
    Dec 2, 2014
    Posts:
    7
    Thank you! This solves all my problems!
     
  4. Nanoflash

    Nanoflash

    Joined:
    Dec 2, 2014
    Posts:
    7
    Still, there is one problem...
    A<sprite anim="0,2,4">B<sprite=0> - in this case, the size of the single and animated sprite is different.
    Unity 2020.1.14 TextMeshPro 3.0.3
     

    Attached Files:

    Last edited: Dec 1, 2020
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    See if making the following changes to the TMP_SpriteAnimator.cs file resolves the issue.

    upload_2020-12-1_13-15-49.png
     
  6. Nanoflash

    Nanoflash

    Joined:
    Dec 2, 2014
    Posts:
    7
    https://yadi.sk/i/fkbHMEJuPOJT1A
    Yes, it works. The size and a place is the same. Hopefully this will be included in the next version of TextMeshPro.
    Thank you!
     
    Last edited: Dec 2, 2020
  7. Nanoflash

    Nanoflash

    Joined:
    Dec 2, 2014
    Posts:
    7
    I would like to see better animation management in the next version. Next method is very useful (for me :)):

    public void DoSpriteAnimation((int currentCharacter, TMP_SpriteAsset spriteAsset, int[] frames, int framerate)

    and tag:
    <sprite anims="frame1,frame2,..,frameK,...,frameN" rate="framerate"> ,frameK - any sprite from spriteAsset
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll add this to the list of feature requests :)

    P.S. You can re-order the sprites in the Sprite Character Table as seen below.

    upload_2020-12-2_17-11-29.png

    If you are referencing sprites by index then changing their order can be an issue. However, if you are referencing these sprites by Unicode code point then changing their order will have no impact on them being referenced in the text but will enable you to change the order with respect to animating them.
     
    Last edited: Dec 3, 2020
  9. HyagoOliveira

    HyagoOliveira

    Joined:
    May 17, 2021
    Posts:
    6
    Would be possible to create a rotation animation?
    Something like this:

    <rotate anim=15> <sprite index=0> </rotate> Text

    Where 15 is the rotation speed per second.
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I can certainly take a look at this when I have time but I am pretty swamped right now.

    On the other hand, you should be able to create a script that you would add to a text object that would rotate specific characters. I would suggest you take a look at the example and scripts used in "23 - Animating Vertex Attributes" which is included in the TMP Examples & Extras.

    In that example, we modify the vertex position of the characters to create some Jitter FX and also change the vertex colors to animate colors. Creating a similar script to rotate all or a specific character would be easy to do.