1
\$\begingroup\$

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.

Screenshot of the problem.

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.

\$\endgroup\$
4
  • \$\begingroup\$ "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. \$\endgroup\$ Commented Oct 1, 2020 at 13:46
  • \$\begingroup\$ That should work. Thanks! Will you make it into an answer, so I can mark it? \$\endgroup\$ Commented Oct 1, 2020 at 13:49
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Oct 1, 2020 at 13:51
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 1, 2020 at 13:52

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.