Search Unity

Question Using a Sprite, I see a white line at certain font sizes

Discussion in 'UGUI & TextMesh Pro' started by dgoyette, Feb 28, 2021.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I use a couple of spritesheets to show keyboard/button bindings in my game. I've found that at certain font sizes, I get some artifacts in the sprite. For example, here's a sprite being used at font size 98:

    upload_2021-2-27_23-30-20.png

    But, at font size 99, it looks like this:

    upload_2021-2-27_23-30-2.png

    That white line above the sprite appears at many different font sizes. Trying many different sizes, I'd say there's about a 50/50 chance the white line will be there.

    Here's the text I'm using in this case:

    Code (CSharp):
    1. Hold <size=140%><sprite="Placeholder_FirstPersonKeyboardInputSpritesheet" index=22></size> to walk more slowly. This may useful when you're near a ledge.
    Is this something anyone has seen before? Is there perhaps a setting I should be aware of for avoiding this?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This might be related to the padding around the sprites being too small where you end up seeing a piece of the adjacent sprite in the texture.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Thanks. It looks like this was being caused by an adjacent sprite in the spritesheet filling directly to the edge of its bounds. I didn't see a way to add padding around the sprites, though. I ended up just making sure the neighbors didn't fill to the edges, but it would be good to know how to get some padding on the sprites in cases where I'd need to use a completely filled sprite that goes right to the edges of its cell.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Due to how bilinear filtering work, it is best to leave 1 pixel between each sprite in the atlas to avoid such potential.
     
    dgoyette likes this.