# How to create pixel-perfect text in TextMeshPro with a shadow?

## Problem

Making the font asset of type Raster creates a pixel-perfect font, but it doesn't have the underlay option inside its material to give it a shadow.

Making it of type SDF (or one of the variants) does, but it's blurred in game view.

See the image for a visual example. The top text uses the SDF variant, whereas the bottom is of Raster type. This is Game View, zoomed in.

## Attempted Solution

I considered using Unity's own Text component, which, strangely enough, doesn't blur in Game View (but does in Scene View). However, to give it a shadow, I need to create a 2nd, black Text object to place behind it with a small offset. This is fine, but then I need to match its value to the main Text's, and I can't seem to do that without checking every frame inside Update(), which is wasteful.

• "I can't seem to do that without checking every frame inside Update()" - Couldn't you do this when you SET the text? Create a styled text component that holds a reference to both the front text and its shadow. Any script that assigns text calls StyledText.SetText("foo"); and then the styled text script sets the two text components' strings at the same time. No need to check for consistency in Update. – DMGregory Oct 1 '20 at 13:46
• That should work. Thanks! Will you make it into an answer, so I can mark it? – verified_tinker Oct 1 '20 at 13:49
• It's not an answer to "How to create pixel-perfect text in TextMeshPro with a shadow" — did you mean to ask how to create pixel-perfect text with a shadow, without presuming the solution must include TextMeshPro? – DMGregory Oct 1 '20 at 13:51
• Fair enough. It solves my problem, so I'm OK with it, but we can wait for a more accurate answer. If it is possible to do this with just 1 TMP, that'd be cleaner and therefore preferable. – verified_tinker Oct 1 '20 at 13:52