Confusing Threesome in Unity: C#, Mono, and IL2CPP

Yadi Yasheng
2 min readJan 3, 2020

C#

To understand Mono, we need to look at how C# compilation works first.

step1: compiletime step2: runtime

Unlike C++, the output of a C# compiler is not something that machines can understand and execute directly. Instead, C# source code gets compiled down to intermediate(IL) code which relies on the Common Language Runtime (CLR) to actually run on the target platform.

Unfortunately, CLR was initially targeted to Windows platform only. So how does Unity manage to build our games for so many different platforms?

Mono

Mono is an open-source implementation of Microsoft's .NET Framework. Basically, a bunch of talented engineers implemented .NET CLR in platforms other than Windows. Power of open source. How amazing is that!

Unity used Mono as their scripting backend to support cross-platform development. So we can write our game code in one place, and deploy it almost anywhere.

Mono is indeed powerful, but it wasn’t a long term solution. Due to the amount of work and time required to develop, port, maintain new scripting features for so many platforms, Unity’s supported .net version was always lagged behind. We were basically stuck on .NET 2.x for years! How do we get the latest C# goodness?!

IL2CPP

Mono served us well, but it was time to move forward. IL2CPP (Intermediate Language To C++) is the new scripting backend unity developed. Basically, Unity ditched mono and made their own toolchain that will transpile IL code to C++ code. And then they make use of the C++ compiler available on the target platform (MSVC on windows, Clang on OSX for example) to produce the final executable.

With Mono out of the loop, we don’t have to rely on Mono’s compiler anymore. Unity swapped out Mono’s compiler with Roslyn, and now we can enjoy the latest and greatest features of C#7

--

--