How Unity Supports Cross Platform Feature

Niraj Vishwakarma
3 min readApr 20, 2018

--

If you are a Game developer or ever tried to look for Game development engines around us then probably you came across Unity 3D Game Engine, which is becoming giant day by day and provides increasing set of tools and environment for 3D and 2D game creation. Unity comes with tons of features inbuilt and it has everything to start your game from scratch, import game assets, write codes, debug efficiency and deploy across all major mobile, VR, desktop, console, and TV platforms plus the Web like as follow -

Unity 3D Supported Platforms

Build once, deploy anywhere. That’s incredible and what makes Unity among the handful preferred game engines to develop rich-feature games. But wait, have you ever thought How Unity made it possible to deploy your game for so many heterogeneous platforms by just writing your code in C#?

By this time you should have several questions in your mind like -

  • - How does c# code run on Android and IOS?
  • - Does not Android use Java while IOS uses Objective-c in native development?
  • - Who converts c# code into machine code that can run cross-platform?
  • - and several others.

Okay, it’s time to know who is doing it for us behind the scene and the answer is Mono. Mono is an open source “Cross-Platform” .NET compatible development framework that comes bundled with Unity. Due to this cross-platform feature of Mono, it becomes possible to support multiple deployment platforms. If we check history little bit, Microsoft released .NET framework in 2000 which was really powerful but did not have support for the non-windows platforms for development. Then comes the Mono as an open source project in 2001 which brings the .NET framework to other platforms including its own c# compiler and CLR(Common Runtime Language). Today Mono supports almost all .NET features and still increasing its set of tools.

If you need more detailed information about Framework then you must check : Introduction to C#, .NET and Mono Framework.

Now the main question comes the way: I don’t have any c# runtime framework on my Android/IOS device then how it’s running the game made in Unity? — With every game made with Unity (or application developed using Mono), there goes “Mono Runtime Environment” bundled with the build which is responsible for further acts as Virtual Machine to run the code on any platform independently. Mono runtime simple converts the compiled Bytecode in the build to native code.

Unity Compilation for Cross Platform

Please note, Mono don’t add the whole framework to the build, unused classes get stripped and the only portion of the framework added which is used by your Game/App. It is also the answer to why Unity creates builds with the higher size and it is justified as it needs to support the cross-platform feature.

VOILA!!! Mono is the champion here. Mono brings the cross-platform .NET compatible features for Unity, you write code in C# and when you make build, it attaches Mono Runtime with it. Further Mono runtime runs your game acting as Virtual Machine on any platform.

About Author: Niraj Vishwakarma, I am a Unity Game Developer in Indian based firm, having skills in the Mobile game, Augmented reality and VR app development and keen to work more on such technologies. I love sports too ;) My social profiles: Email | LinkedIn | Twitter

Sources:

https://en.wikipedia.org/wiki/Mono_(software)

https://sometimesicode.wordpress.com/2014/02/19/how-does-unity-export-to-so-many-platforms/

--

--

Niraj Vishwakarma

I am a Unity Game Developer and sports lover. I am keen to work more on future technologies like AR and VR. Contact mail id: Nirajv21@gmail.com