Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity - does the current version generate native code or not?

Tags:

c++

c#

unity3d

Here I can see that Unity documentation says that it is 50% slower than native code: http://docs.unity3d.com/412/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html

Here it says that there is an IL2CPP compiler, that obtains c++ code which is compiled into native code. So is it now creating native code, or is it 50% slower? :) http://blogs.unity3d.com/2015/05/06/an-introduction-to-ilcpp-internals/ http://blogs.unity3d.com/2014/05/20/the-future-of-scripting-in-unity/

like image 467
Narek Avatar asked Jun 15 '16 11:06

Narek


People also ask

What version of C# does Unity 2022 use?

New syntax and language features. Using the updated scripting runtime gives Unity developers access to C# 8 and a host of new language features and syntax.

Does Unity use C# 8?

Unity support for C# 8 has started on version 2020.2 and C# 9 has started on version 2021.2. Be aware that not every C# 8 and 9 feature is supported by Unity, like: default interface methods. indices and ranges.

Does Unity have its own compiler?

Unity Technologies Unity doesn't use the Visual Studio compiler, it has its own.

Is C# compiled in Unity?

To compile C# source code in a Unity Project, the Unity Editor uses a C# compiler. The Editor passes a default set of options to the C# compiler. To pass additional options in your project, see the documentation for Platform Dependent Compilation.


1 Answers

The documentation from Unity you referenced is pretty old, and even at the time it is written, I would really wonder about those performance numbers. In general, performance is much more complex to measure and report than one number like 50% can express.

If you want to learn more about IL2CPP, check out this blog post series.

Based on our benchmarks at Unity, we're seeing better performance for script-bound code with IL2CPP than with the Unity version of Mono. You can find one benchmark we have published here.

There are a few caveats to keep in mind though:

  • Unity uses an old version of the Mono runtime (circa 2011). Newer versions are better - and we are working on upgrading the runtime now.
  • Most game code is not script-bound, it is usually GPU-bound.
  • The generated C++ code is still providing the safety of a managed language, so it makes array bounds checks, for example.
  • The performance difference between the Mono AOT and the IL2CPP compilers will vary based on the platform. On some platforms, the Mono AOT compiler produces machine code as well as a C++ compiler. On other platforms this is not the case.
like image 121
Josh Peterson Avatar answered Sep 20 '22 02:09

Josh Peterson