Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

[Solved!] Monospace fonts are not rendering as monospaced when centered

A topic by Spacey Batotelli created Jun 18, 2018 Views: 1,404 Replies: 6
Viewing posts 1 to 7
(3 edits)

In my current project, I'm using a monospace font for UI counters so that the numbers don't jitter around when they change, but Super Text Mesh ignores this and does not evenly space them when the text alignment is set to Centered. This does not happen with Unity's default Text Mesh object, nor does it happen when alignment is Left, Right, or Justified. Is this a bug or is there a way for me to adjust this?

Developer

Hmm... I'm having trouble reproducing this, could you post a screenshot of your editor window, including STM's inspector?

I uploaded a .gif here:

https://imgur.com/a/RPzH8Ss

To be more specific, what's happening is that the text is re-centering itself when the numbers change. I've tried it with different monospace fonts so it's not just the font I'm currently using. I'm also using Unity 5.6.3f.

Developer

Okay yep, I'm able to repro it now. (I'm testing this with courier btw. Top mesh here is STM, bottom is UGUI)

I think this is caused by... the middle alignment only takes the width of the letter into account, not the width + advance. When I right-align a UGUI Text component, the text is not flush with the right side of the box, but with STM it is. This is a great catch, but I'm worried about changing this, since it would effect all text meshes, not just monospace fonts. I'll have to come up with a way for this behaviour to only effect monospace fonts automatically, somehow.

I'll write this down for sure, but if you align stuff to the left, it should work for your purposes for now?

Yeah, I can "solve" the problem by aligning to the left and then moving the text box so that it's center.

Anyway, that's fascinating info! I'm not overly code-savvy so I don't know how practical it would be to pull off, but perhaps the issue can be solved without introducing problems by adding a monospacing feature in the future? Like, maybe STM could be set to render a letter every X distance regardless of its actual width, effectively allowing any font to be monospaced.

Thanks for the fast reply! Disregarding this hiccup, I'm having a great time with this plugin.

Developer

Reviewing this again as I'm fixing bounding box issues, STM is actually supposed to use a character's advance when deciding on the width of a box, so I will be changing this behaviour to work the way it should! Sorry about all this, but thank you for catching this.

Developer

This behaviour should be working correctly as of v1.8!