Notifications
Article
Emoji support in Unity 2019.3 and older
Published 9 days ago
12
0
At first I thought it'll be easy >.<

My experience with emoji implementation

Once I was asked to add emoji support to our product we were poring to mobile devices.
As always I started googling, to my surprise I couldn’t find any specific solution to my problem. That’s kinda awkward because it feels like a core feature in terms of platform support.
What’s interesting, when I looked at games available in the AppStore (iOS) most of them didn’t support emojis! What the heck!?
During my web trip I stumbled on useful informations and packages that helped me form my take on emojis. I’d like to share this piece with you!

Getting started

You will need these assets first:
  1. TMPro package with Essentials imported
  2. Emoji sprite sheet texture for target platform
  3. Emoji sprite assets (iOS & Android)

NOTE
Sprite assets were created using tool that is part of this package [PING]
Since it is not necessary to have yet another package in the project I decided to use just one of the features: Sprite Emoji Importer.

You can find all fo the files and configurations in sample project I created here: [PING]
It is ready to build for both iOS and Android platforms.

SECOND NOTE
Even though the process is quite easy you may find some of the emojis to create visual artfacts.

Implementation

With the preparation done, all we need to assign the SpriteAssets to TextMeshPro Settings.
By default Settings asset is located at path:
Assets/TextMesh Pro/Resources/TMP Settings
This applies for all of the TMP texts in your project. You can as well assign the SpriteAsset to specific TMP objects in your scene.
Just assign the proper SpriteAsset and you’re done.
Is that all????
Well, yes if your build target is Android.

iOS Xcode fixes

During my study I found many issues in various unity versions. All of them reside in the script:
Classes/UI/Keyboard.mm
Apparently Unity team has done wonderful job to fix all the crashes that did happen when one tried to type an emoji into Input Field which reached it's character capacity.
Except....

Can't type emoji in 2019.3.0f6

They forgot to check whether an Input Field has got character limit set in the first place!
To fix the issue in Keyboard.mm check the following if statement line 640 (in my case) to include _characterLimit check.
#if !FILTER_EMOJIS_IOS_KEYBOARD // If the user inserts any emoji that exceeds the character limit it should quickly reject it, else it'll crash if (newLength > _characterLimit && StringContainsEmoji(text_)) { return NO; } #endif
Result:
#if !FILTER_EMOJIS_IOS_KEYBOARD // If the user inserts any emoji that exceeds the character limit it should quickly reject it, else it'll crash if (newLength > _characterLimit && _characterLimit != 0 && StringContainsEmoji(text_)) { return NO; } #endif

Important NOTE
If you apply the above solution to your Xcode project it may get erased next time you build the product.
In this case you can edit the Keyboard.mm source file which is located here: /Applications/Unity/Hub/Editor/2019.3.0f6/PlaybackEngines/iOSSupport/Trampoline/Classes/UI/Keyboard.mm
This change will affect every build you make in the future.

FINITO

Alright folks, we’ve reached to destination. I hope you managed to add the emojis to your project. o/
Still got some issues? Feel free to contact me here [PING]
See ya!
Radosław Krystkowiak
GAMEPLAY | UI | IOS | ANDROID - FREELANCE - Programmer
3
Comments