Unity Text

Unity Text Solutions

So we all know that text in Unity used to be a right pain in the rear. At least doing it without a gazillion draw calls using OnGUI. Things have changed slightly with all the current 2D solutions and Unity’s text mesh but I feel like each one fails at something, even be it a small thing. Through investigating a “read to me” system for my wife’s new game, Notespace¬†Beat, I have taken a good hard look at some of the best solutions out there and am giving you a quick run down. Before we get into it, I had a very specific set of text requirements that I needed to satisfy. I need to be able to change size easily, change the style of the font (bold, italic), change the line spacing and pretty much everything you can do with in a text area in photoshop. It needs to be light and I need to get to the positional data of the text so I can find out if a user tapped a word.

First up, Unity Text Mesh.
I have never really played with Text Mesh before this project because I was always under the assumption that it would not work with my current work flow and 2D solutions. I was wrong about that and there are a lot of things to write home about here. First off, the dynamic font generation is pretty dope. Not having to make new font maps every time I change my font or its size is wonderful. Secondly, it supports basic inline styling. This means I can change every letters color, its size and make it bold/italic all with in the text area, using simple HTML like commands. It has line spacing, anchoring and alignment but does not have character spacing / kerning. Geeze guys! Unity, you built the perfect text solution but forgot a fundamental thing like that… sigh! I am sure there is a reason and I hope to find out what it was! I know that many game developers are not concerned about text but coming from a design heavy background, text is really important. So Unity, I give you huge props for Text Mesh but an A- because of the lack of character spacing. When I was running my performance tests, it all seemed great, just a single draw call.

Second, 2D Tool Kit text.
I have been bouncing between NGUI and 2DTK for a while now. I mainly used NGUI because of predefined project requirements but its become my favorite 2D solution. Sprite dicing is a gift from the gods! Anyway, their text tool is also pretty great. The tool is well laid out, it has a word wrapping gizmo, a nice big text box area in the inspector to type in and plenty of options. They have kerning, character spacing, line spacing and gradient text options. What it doesn’t have, compared to a few other 2D tools is the drop shadow and outline options which is a pity because the drop shadow stuff comes in useful. They do have some pretty powerful inline styling options though. Unfortunately its not all that Unity’s Text Mesh has but they are still really good. 2DTK allows you to basically control the colors of every character. Not only color, but gradient too! Another thing they have going on behind the scenes is great font atlasing. Instead of just dumping in your font sheet, 2DTK will break it up into characters and pack your mixed atlas perfectly! Yummy space savings!

Third, NGUI’s text.
NGUI text is industry standard in most of the companies I have worked in. Its reliable and their reference atlas features allow for great flexibility between resolutions and languages. Big win there. It has character spacing and line spacing but line spacing is hidden under a “Spacing Y”. It has a few text effects; color gradient, outline and shadow and now comes with some interesting resize & flow tools for more intuitive layout. But wait, there’s more! NGUI also has the ability to use dynamic fonts! This means that it uses Unity’s new TextMesh font system and allows you to make good looking text at any size. Really nice, just a pity it didn’t carry over the inline styling. The new text sizing features can also get annoying, especially if you are used to the old NGUI layout, but I am open. All in all, solid stuff.

Lastsly, EX2D.
A lot of people are not familiar with ex2D but it is a 2D solution with a lot of potential. I was a huge believer in it two years ago but alas, it had some issues that pushed it behind other solutions. Its biggest issue was that when ever you updated to a new version, all the internal GUIDs would change and you would lose all your sprite references! This means that you would basically have to layout your entire project again. This was mainly due to them releasing their package wrapped up in a dll. There were also a few SVN issues but I still mention it because it is evolving. They sorted out these two issues as far as I know but its still a little light on documentation. Anyhoo, their text tool is pretty good. It has all the base options of NGUI and 2DTK combined (gradient color, shadow, outline, kerning, line spacing, character spacing) but has something called shear. This allows you to skew the font so you can force italics without baking a new font. Very useful if you are doing a lot of mixed font work.

Whats the bottom line?
For me, for this project, Unity’s Text Mesh. It has almost all I need. I have not investigated the code side yet as far as calculating where a word lies in space but the inline bolding, italics, size change and color change are a bit of a god send for me. I will do a post-mortem and let you know how it goes. I will look at integrating Text Mesh into my pipeline permanently but, in general, I use the character spacing more than the inline styling so I will have to stick with 2DTK or NGUI, depending on what 2D solution my project is going to use. Either of those two will serve you more than adequately, but for text specific, NGUI probably wins out with dynamic fonts. Most companies have started to use NGUI for UI and 2DTK for gameplay because they can play well together. I will be looking at working with a 2DTK pipeline only for future projects, mainly because of its awesome atlasing tools. I would like to say well done to NGUI, 2DTK and ex2D for providing such excellent tools. Keep up the good work!

—UPDATE—

I implemented Unity’s Text Mesh but alas, getting to the mesh data to see how long a string is or play with the verts is non existent. I was going to add my own character spacing but I cant because of this. So I am switching to 2DTK to see what I can do there. It was pretty simple to edit the text mesh system to add skewing so that I can get italics and am waiting to see if Unikorn will fold it in. Currently working on their inline system to see if I can do the italics inline. Then most of my issues will be addressed.

—UPDATE—

I have been able to add inline skewing (italics), custom character spacing and font size with in the 2DTK text mesh. If you want, just shout and I’ll send. The only thing we can do inline is bolding but thats par for the course really.

—UPDATE—

Text Mesh Pro! Oh … my … god! This is the ultimate text tool. The above is like child’s play in comparison which is saying a lot. Get it now at the Asset Store. I will be hopefully writing an article about that in the weeks to come. Its a huge step forward in text rendering in Unity!

References
Unity Text Mesh
http://docs.unity3d.com/Documentation/Components/class-TextMesh.html
http://docs.unity3d.com/Documentation/ScriptReference/TextMesh.html

NGUI
http://www.tasharen.com/?page_id=140

2D Tool Kit
http://www.unikronsoftware.com/2dtoolkit/
http://www.unikronsoftware.com/2dtoolkit/features.html#text