Unity3D, why "scripting runtime version" is .NET3.5 but "api compatibility level" is .NET2.0? What do the two options in PlayerSettings actually mean?

10,872

What does .NET version in "scripting runtime version" and "api compatibility level" of Unity Player Settings actually mean?

API Compatibility Level:

Just an option given to you to specify how the compiler should compile the project. They are the-same .Net version. See below for what you get for each option.

.NET 2.0 Subset

  • Reduces app size
  • Increases startup time makes
  • Some API's are stripped out by default in order to accomplish the things mentioned above. This mostly includes .NET socket or network API.

.NET 2.0 is the opposite.

  • Has larger build size
  • Start up time is a bit longer
  • Includes possibly every standard .NET API that is non platform based in the build

Scripting Runtime Version:

This is where you chose which .NET version you want to use. Changing this will let you use the select the .NET API and runt-time version.

So, selecting .NET 4.6 let you use the .Net 4.6 API to code your code and Unity will include .NET 4.6 runtime in your game. The-same thing applies to the .NET 3.5.

Wonder why they all have "Equivalent" as post fix? That's because some of the API's and features are either removed or stripped out in the Unity. You will notice this but this only applies to few amount of .NET API. Most of them are supported.

And, when I set "scripting runtime version" to ".NET 4.6 Equivalent", I can choose "api compatibility level" as ".NET4.6". But why these two option values are the same at this time???

Nope. That's not true. You only see both options in the "Scripting Runtime Version" option but you can't select ".NET 3.5" if "API Compatibility Level" is set to ".NET 4.6".

If you try this, Unity should restart then select ".NET 3.5" for "Scripting Runtime Version" and automatically change "API Compatibility Level" from ".NET 4.6" to ".NET 3.5".

So, if ".NET 4.6" as "API Compatibility Level", you must also select ".NET 4.6" as the "Scripting Runtime Version".

Which .NET version is Unity3D actually using?

The one you selected under the "Scripting Runtime Version" menu.

I wonder why I only have to select ".NET 2.0" or ".NET 2.0 Subset" for "api compatibility level" when setting "scripting runtime version" to ".NET 3.5". When "scripting runtime version" equals ".NET 3.5", I think "api compatibility level" should be ".NET 3.5" or ".NET 3.5 Subset". That is weird here in Unity. What went wrong here?

Licensing.

There was a licencing issue. Unity's company's only way to update the run-time was to pay a great amount of money to Xamarin since Xamirin made that mono run-time Unity is using and is under the LGPL. They didn't want to do that. I noticed they were able to update mono run-time after the partnered with Microsoft and joined the .NET Foundation last year.

Share:
10,872
unolee
Author by

unolee

Updated on June 05, 2022

Comments

  • unolee
    unolee almost 2 years

    I've been using Unity3D these days and checked manuals about .NET system. But felt very confused.

    In Unity3D Player Settings, there are two options called "scripting runtime version" and "api compatibility level".

    When I set "scripting runtime version" to ".NET 3.5 Equivalent", I can choose "api compatibility level" between ".NET 2.0" and ".NET 2.0 Subset". But why these two option values are different? Shouldn't they refer to the same .NET version value? What does the word ".NET" in the two different options mean? Which .NET version is Unity3D actually using?

    And, when I set "scripting runtime version" to ".NET 4.6 Equivalent", I can choose "api compatibility level" as ".NET4.6". But why these two option values are the same at this time?

    On the other side, I found some manuals on Microsoft Websites introducing .NET system, and they say there is .NET Standard, .NET Framework, .NET Core and Mono. There isn't standalone ".NET" entity at all.

    So, what does .NET version in "scripting runtime version" and "api compatibility level" of Unity Player Settings actually mean?

    Update

    Facts:

    1. There is no "scripting runtime version" option before Unity2017.1.0

    2. .NET Framework has good backward compatibility, which means .NET 2.0 components are able to run on .NET 3.5 without break.

    3. When we are talking about .NET version, it always refers to version of .NET Framework.

    4. Unity3D is updating runtime to .NET 4.6.

    Infer:

    1. .NET Framework has good backward compatibility, so does mono.

    2. Unity3D uses a mono as runtime, which is equivalent to .NET 3.5

    3. Unity3D only uses .NET 2.0 features to compile but has a .NET 3.5 runtime to run on. That's why "api compatibility level" is ".NET 2.0" when "scripting runtime version" is ".NET 3.5"

    4. Unity3D is updating to use .NET 4.6 features on .NET 4.6 runtime. That's why "api compatibility level" is ".NET 4.6" when "scripting runtime version" is ".NET 4.6"

    Updated again

    Here is another relevant question: Why does Unity use .NET 2.0 when Mono supports .NET 3.5?

    And a relevant thread: https://forum.unity.com/threads/to-linq-or-not-to-linq.223887/

  • unolee
    unolee over 6 years
    Thank you for answering! But you may get some misunderstanding. I wonder why I only have to select ".NET 2.0" or ".NET 2.0 Subset" for "api compatibility level" when setting "scripting runtime version" to ".NET 3.5". When "scripting runtime version" equals ".NET 3.5", I think "api compatibility level" should be ".NET 3.5" or ".NET 3.5 Subset". That is weird here in Unity. What went wrong here?
  • unolee
    unolee over 6 years
    So nice of you. I hope I get it.. All in all, you mean that the .NET version of "API Compatibility Level" makes no sense. The only thing that makes sense is Subset or not. And the .NET version of "Scripting Runtime Version" is the true one who really determines .NET version actually used in Unity3D, right?
  • unolee
    unolee over 6 years
    I updated my question and listed some assumption. Could you please help me out further? I would appreciate it very much.