Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

TextMesh Pro How to Set a Sprite's Size

Discussion in 'UGUI & TextMesh Pro' started by John-B, Nov 19, 2018.

  1. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,250
    I need to add some inline images to a rich text field. I followed the very detailed instructions, created the atlas and added the tags, and the images show up in the field (referencing by sprite name didn't work, but by number does). But I can't find any way to set the size of the images. Line height doesn't work. Changing the font size changes the image size, but causes all kinds of alignment problems - the image is off the edge of the field and the image overlaps the following text.

    Is there a simpler way to insert an image and set its size without having to adjust everything else? I have a simple HTML document that has paragraphs of text with images in between the paragraphs that I need to reproduce. Unity rich text docs list a <quad> tag for images, but I don't see that tag listed for TMPro. Is there a better way to do this with TMPro rich text or are (large) inline images not supported?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The size of sprites is normalized to the height the current font / line of text. At scale = 1.0, the sprite's height will be from baseline to ascender and its width kept proportional.

    The scale of individual sprites can be set in the Sprite Asset for each sprite.
    upload_2018-11-19_13-25-25.png

    Referencing by index, name or unicode should work.

    The <size> tag will affect text elements as well as sprites.
     
  3. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,250
    Thanks. Setting the sprite size works like setting the font size, the image is shifted and overlaps text. Looks like rich text doesn't work like HTML when it comes to inserting images. I think it will be easier to just divide the text up into blocks and insert images between the blocks. It's in a scroll rect, so setting up a layout group should be quick and easy, relative speaking.
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The Offset X and Offset Y control the positioning of the sprite. The Adv control how much space is inserted after it. With those values you can ensure the image will not overlap the characters.

    Please post an image of the type of layout / results you are expecting.
     
    Last edited: Nov 20, 2018
  5. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,250
    Adjusting the offset moves the image around, but the Adv setting does nothing that I can see. But that's OK, I can add spaces in the text to allow for the images. So this will work. Thanks.

    Attached is an example of the web pages I'm trying to reproduce, just paragraphs of text with images in between.

    HTML-Sample.jpg