Emoji support in Unity 2019.3 and older

My experience with emoji implementation

Once I was tasked to add emoji support to our unity project we were porting 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:

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.

Still got some issues? Feel free to contact me here PING

See ya!

Debugging mobile games in Unity

But it works on my end... :O

Greetings friends, today I will present you tools I use everyday as a Unity Developer to debug games and applications during development cycle.

Debugging is a process of identifying and solving software issues which prevent its correct operation. In other words BUG FIXING. What I consider as a bug:

In this post I will familiarise you with:

In the start I'll go with total basics, so feel to jump to the section of your interest 🙂

Without further ado, Let's Go!

Unity toolset

The engine itself provides some handy instrument to help you run diagnostic. In most cases this will be enough for you to proceed from investigation to fixing phase. Let’s start with the basics.

Console Window

Unity Developer’s best friend is the console window which resides in the bottom area of the editor. Treat this window as your most valuable tool, don’t you ever dare to close it as it is where you’ll notice any warnings and errors regarding your application runtime.

Console in action.

Double clicking should bring you to the IDE and highlight the line where error occurred. Too easy, right?

I met people who didn’t know about one useful feature of unity’s console window: COLLAPSE!

With that enabled console window will stack all same error logs in one line.

Collapse example

Sometimes diagnosis ends here but not always. There are times where it’s just the beginning of looking where did you loose the data you want to access right now.

Profiler

This is more advanced tool which is used to detect mostly CPU, GPU or memory related issues - Optimization.

You can add profiler window by going to Window -> Analysis -> Profiler

Here you can see a ton of data that describes your app. The three top ones are the most important, let me elaborate on those.

CPU Usage

Displays how much time it took to render a frame as well as details of every tracked task. If all the required assignments need below 16ms to complete, it means your game in that particular second runs on more than 60fps.

Remember that running the game in the unity editor will add some overhead to the execution speed. If it's possible always profile the product on target device.

When looking for a potential frame drop cause one should look for the spikes to appear on the graph. Simply click on it and see the details.

Sample presentation with switch to hierarchy

In my case task that causes frame drop is rendering. It means there could be too many complex objects in the camera view that want to be rendered (draw calls). I cover this in the next section.

You can keep unfolding the hierarchy and go deeper into the call stack. That will lead you to the core of the call stack. The unoptimized code may appear at any depth so keep your eyes wide open!

In some cases you may notice a task named “Gfx.WaitForPresent” on the top of the list. If it happens regularly you should focus on graphics optimization as your project is GPU bound. In other words your CPU is waiting for the Graphics to complete it's tasks.

Rendering

This tab is all about geometry, it contains information about:

When optimizing your game in terms of rendering, developer should focus on lowering the number of draw calls in the first place.

Draw call is a request from an object that wants to be displayed on your screen during a frame. It contains informations about shaders, materials, state in form of CPU work that is passed to GPU.

Remember the golden rule: The lower the better.

The quickest way to lower the draw calls is either:

You can read more about graphics optimization here:
PING

Memory

Here the details of memory allocation can be seen.

Devs should always be aware of the total operational memory of target devices. When it runs out the game will be terminated due to insufficient resources.

Short on maintaining the memory allocation in unity:

Find out more:

Unity post about: GENERAL Optimization
Unity post about: MOBILE Optimization

If by any reason you need to access more data within profiler window, you can enable Deep Profiling: PING

Debugging for Mobile

During the past two year period Unity team has put a lot of effort into integrating editor debug experience with mobile devices.

Right now the easiest way is to connect your device with editor either by

Or

With device connected the debug flow is the same as described above in the built-in tools section.

Now the experience is flawless, but in the past there were many bugs or no features like this at all. That’s why I’ll show you ways to directly connect to your mobile device logs.

Android

Say hello to good old Logcat. This tool comes bundled with Android SDK. It prints out to console system logs. Those can be filtered by adding arguments in the command line.

Assuming you already have downloaded the Android SDK these are the steps to follow to use this tool:

Now you’re ready to go.

The command I use in most cases is:

adb logcat -s Unity

The -s argument is associated with filtering all the logs to show only the ones tagged with ‘Unity’. This way you’ll see only logs from your game.

You can find more about logcat and it’s options here: PING

iOS

Mac users have access to two essential development tools:

Xcode

There is much I could say about this software, but to stay short I'll describe it as build&publish environment. When running your game on iOS device a console should appear in the bottom. It is where you can search for any errors or messages.

/Remember these logs point to Xcode project files, not Unity ones!/

Instruments

Instruments can be used to get some general data of app allocations, CPU and GPU usage, device temperature etc.

When launched one needs to select the first instrument, but you can add more later.

To get the data press Record button.

Voila! Looks almost like Unity’s profiler.

How to detect app crashes in production

Mmmm, your app is released. Feels good, eh?

But then you enter google console and see hundred of crashes happening across the whole globe.

Don’t panic.

Crashlytics come to the rescue! You probably figured it out, these are like Analytics, but analysis is done only regarding crashes.

It not only shows when and where did it happen, but also running OS, device model, LOGS.

With logs in hand you can surely solve the issue in no-time!

One service I could recommend is Fabric PING

Conclusion

That was a brief description of debug tools available for developers. As you can see, there are plenty ways to diagnose your app, hope you enjoyed the text.

Let me know if you’d like to see more in-depth article about optimization in the comment section below. If I can be of any help regarding you project, please contact me 🙂 PING

March onwards, let’s fight some bugs!