Unity from right to left

Unity from right to left

As it turns out, people in the Middle East and Northern Africa also enjoy video games. A study showed that Saudi Arabia, Iran, and the UAE alone boasted more than 68 million gamers in 2020, the video game market in that trio of countries clocking in at a staggering two billion dollars! With that said, this part of the world isn’t renowned for its knowledge of English—according to the EF English Proficiency Index, average level there is assessed as low and even very low. And that gives game developers and publishers an excellent reason to think about localizing their projects for the region.

There’s a lot of things that bring Egyptians, Iranians, Moroccans, Pakistanis, and Syrians together. In particular, that’s their script, with their native languages all based on Arabic. The familiar intricate letters are used in twenty countries from the Atlantic to the Himalayas.

At first glance, developers and localizers might think it’ll be no more difficult than working with Korean hangeul or Japanese kana. We take the words we need (for example, “New game,” “Settings,” and “Log out”), translate them into Arabic (, , and ), and drop them into our Unity project. Here’s what comes out:

Looks fine, but it doesn’t mean anything, does it? We’re not alone there—our Arab players wouldn’t understand it either. A closer look tells us that the text Unity returns doesn’t look anything like what we got from a translator. And that’s a problem.

Unity doesn’t originally know what Arab graphics are. This writing system uses a word order we’re not used to: right to left, with the letters in each word all connecting to each other (with a few rare exceptions). But Unity returns Arabic characters in left to right order and doesn’t connect them at all, the same approach it takes to European alphabets.

Fixing this is going to take some work. For starters, let’s look at some backstory facts.

The very first tools Unity used to create text were GUI Text components. They returned two-dimensional text on the screen, with regular TTF files for font resources.

But the functionality offered by standard components wasn’t enough to make really good-looking writing, so the Unity developers built TextMesh components. They’re lines of text in a three-dimensional grid, sometimes called a mesh, that is generated using regular TTF font files.

Of course, plenty of people wanted to improve such a valuable tool. Digital Native Studios, a third-party developer, came up with the TextMesh Pro plugin. While it also generates font resources based on TTF (and OTF) files, those font resources are made of a material, a texture, and a character table. The text components it comes up with can be scaled and rotated without sacrificing quality, and visual effects like shadows and contours can be added too. Not only that, but new components can interact with the surrounding environment by reflecting light from nearby sources.

The TextMesh Pro plugin turned out to be so successful that it was built into Unity since Unity 2018.1 version. That is the plugin we will use for our project.

But TextMesh Pro by itself isn’t enough to fix our problem. While it allows you to change the text direction, it doesn’t yet know how to connect letters within words. There’s another setting we need. As of right now, there are several plugins for writing right to left: Easy Alphabet Arabic, Arabic Support, RTLTMPro, and others.

The most advanced solution is the Easy Alphabet Arabic plugin. It supports all the different graphical interface elements in Unity: buttons, text fields, entry fields, and so on. In addition to some Pushtu, Kurdish, and Sindi, it also supports the entirety of modern Arabic, Urdu, Farsi, and Uyghur. And it costs $20.

Let’s take a closer look at the free and still highly functional plugin RTLTMPro (Right-to-Left TextMesh Pro).

1. We shall install the plugins: TextMesh Pro and then the latest version of RTLTMPro from its GitHub page.
2. Copy to the clipboard the Unicode for the Arabic symbols we need: letters, numbers, and diacritics (vowel markings). They’re in the LetterRanges.txt, NumberRanges.txt, and TashkilRanges.txt files that are part of the RTLTMPro package.
3. If you don’t yet know how to make TextMesh Pro font resources, now’s the time to learn:
i. Import the OTF or TTF file for the font you need (make sure it supports Arabic characters) by dragging it over to the Assets panel in Unity.
ii. Call Window > TextMeshPro > Font Asset Creator.
iii. Drag the font file to the Source Font File field.
iv. Copy the Unicode ranges for the Arabic characters you need (for example, the main set is 0600-06FF) to the Character Sequence (Hex) field.
v. Click Generate Font Atlas.
vi. Click Save.

Your TextMesh Pro font resource is ready to go. It is saved into the folder with the source files for the font.

4. Create text objects in the platform using elements from the RTLTMPro packet (they can be found in with the standard interface elements: GameObject > UI > [element type] – RTLTMP).
5. Set the font resource we generated in step four for each new text object.
6. Add the translation and come up with your text:

That’s much better! All the letters in each word are connected the way they’re supposed to be, the words are in the right order, and our Arabic-speaking players can finally enjoy the game.