In a text-heavy program, such as Clinical Encounters, it’s essential that the text is clear and easy to read. That means both in content and rendering. Here, our developers outline why and how we decided to switch our text rendering to utilize TextMesh Pro.
Why Switch To TextMesh Pro?
Unity’s default text handling often causes text to look blurry, unattractive, and is difficult to read. If your project has limited text, like what would be in a start screen or pause menu, there are ways to make the text look slightly better with size and scaling adjustments, as well as strategic font choices. These fixes are not viable, however, if you are creating a text-heavy program such as Clinical Encounters. To make the text readable, we would need to have an extreme amount of extra white space and the ability to add kerning. Unfortunately, you cannot do this with the default text handler. We found the solution to both the need to have sharp text and the need to add in kerning with the TextMesh Pro asset. Due to the use of Signed Distance Field, rendering TextMesh Pro is more versatile and customizable, less expensive on system resources, and looks much cleaner and more refined with any resolution or point size when compared to the stock Unity text handling.
Now that we had found our perfect text solution, we ran into another, more daunting, problem. We had 137 prefabs, each with a range of 3 to upwards of 40 text components, and three different scenes which also contained a large amount of individual text components. We now had to switch all of these components over to TextMesh Pro, do clean up of the visual project by adding in kerning and re-adjusting the extra white space, and change the way the code handled text input loading. We decided to break this process up into three parts. First, a team member would go through and do the initial switch – a process that is outlined below. Then another team member would go through and do visual polish – adding in kerning, removing excess white space, and changing font sizing as needed. During this time, a third team member would make the necessary adjustments to the code and ensure all references were still intact.
The Process Of Switching
The first step in the switching process involved multiple steps, as demonstrated in this blog using the game object TodayLabel which will display the text “Today’s Visit”. This part of the process called for great attention to detail and patience. To make this process easier, we created an empty scene in which we could drag an empty prefab in and edit it without having to worry about mistakenly saving scenes with extra game objects applied.
First, the game object that needed to be converted was found. It was then duplicated such that a copy of the original could be kept for reference purposes, but would be deactivated. After clean up and testing was completed, to ensure the transfer went well, these deactivated text game objects were deleted. In the Inspector tab on the left, we can see that the text is typed into Unity’s stock text handler.
Because “Paste Component Values” does not work across different components, the previous values had to be re-entered manually. This required that the font, style, size, horizontal and vertical alignment, and color to be noted. The position of the textbox was also noted, in case it was slightly altered initially by the TextMesh Pro component. Once these values were checked, the stock text script was deleted, the new TextMesh Pro component was pasted in, and the values were re-entered and applied.
As for the code changes, it simply involved changing out references to the UnityEngine Text, InputField, and Dropdown classes to be their equivalent TextMesh Pro classes. Thankfully, TextMesh Pro operates almost identically to Unity’s classes, so most changes didn’t require much work other than changing a variable’s class name. This did mean, however, that any script variables and method calls with old Text parameters had to be updated. This would break references in the editor as well, but it was simple to reassign them after the switch.
This process was then repeated for all of the game objects that needed to be converted. If the game objects were contained in a prefab then the prefab would have to be updated so the work was not lost.
The results speak for themselves. Here is TodayLabel before and after the TextMesh Pro conversion. The difference in clarity and readability, especially up close, is strikingly significant.
This change allowed us to remove a lot of unnecessary white space, but still have our text easily readable on various window/screen sizes. While transferring from the default text handler to TextMesh Pro was a large task that took a little over two weeks to accomplish, it left Clinical Encounters looking more polished and professional looking. It also helped us address usability issues that had been brought up during interface development and internal usability testing about text being difficult to read and the large amount of scrolling a user would have to do to see all of the information, due to the large amount of white space. It will also, hopefully, help decrease the strain on a user’s eyes that was caused by having to attempt to read a large amount of blurry text on a screen.
Updating Unity For TextMesh Pro
As of Unity 2018, TextMesh Pro is now included by default in the Unity Package Manager where you can find While it is always better to remain in the same version of Unity that you started a project in, if you find yourself needing to update to Unity 2018, as we did, and you have TextMesh Pro elements, you will need to run an automatic conversion process to update the GUIDs and FilelDs. We updated to 2018 after our TextMesh Pro conversion was complete and found the update process very easy. Though we had a large amount of TextMesh Pro elements that needed to be converted, the process didn’t take very long at all – only a few minutes. There were a handful of instances where references were lost, but those were quick to find in testing and even quicker to fix. Just because our upgrade experience went smoothly does not guarantee it will for every project, so please remember to save a recent backup of your project just in case.
You can read more about the Clinical Encounters platform at its website.