Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Which is the .NET version used in Unity 2018.4?

Discussion in 'Scripting' started by gambr, Aug 13, 2019.

  1. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    Dear All,
    I only found that "Scripting runtime version is 4.x equivalent" but is there a place where I can find the exact version of .NET used? 4.WHAT?

    Regards,
    Gianni
     
    dan_ginovker and adnanzmn97 like this.
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Unity has their own runtime, which is why they're not explicit about the exact version.

    So to answer your question, what do you need to know this information for? If it's for API coverage, then Unity supports .NET Standard 2.0, which is supported in NET Framework 4.6.1. But that doesn't mean that Unity and .NET Framework 4.6.1 has the same API surface.
     
  3. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    Hi Baste,
    I would like to use Json.NET framework for serialization (Unity implementation is limited). I tried to add it to my project but I get a bunch of errors. So I would like to understand if that may be related to the .NET version.
     
    osama2o1ooo and dan_ginovker like this.
  4. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    I realized there is a "JSON .NET For Unity" package so it seems there is a reason why simply adding the downloaded Newtonsoft.json framework does not work in Unity.
     
  5. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    @gambr
    The last few versions (since I think 11.01 when he began targeting Standard 2.0) have worked fine for Unity, outside of an issue on iOS- how are you adding it exactly? If you're just downloading the whole repo and trying to drag the source files in, that probably won't work- most repos not aimed specifically at Unity have symbols set up for preprocessor directives, choosing which features work or don't work with any given build target. Those aren't going to work right without the actual symbols set. You need to build it for .NET Standard 2.0 first in (for instance) Visual Studio, or just download the zip from the "Release" list, unpack it, and choose the Standard 2.0 version of the library to include.

    You can also use this fork if you want something that fixes the iOS issue. Don't bother with other assets and repos with forks of Json.NET aimed at Unity- they're all outdated and not maintained properly. The one you referenced I think only has version 8, so it's at least 2 years old.
     
    Last edited: Aug 13, 2019
  6. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    Thanks Lysander,
    so which Json.NET you suggest, considering that iOS is not a target platform we support?
    Should I build (or download) the library for .NET Standard 2.0 even if I set "Scripting runtime version" to ".NET 4.x equivalent" and "API compatibility level" to ".NET 4.x" in my Player Settings?
     
  7. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    I've never used the repo I linked that's supposed to fix the iOS issue, so I can't really "recommend it" as such, but it's easy enough to download the Standard 2.0 version of the latest official Json.NET release. If you find that it gives you problems somewhere down the line (though I've had none), you can try out the other one.

    And yes, ".NET 4.x equivalent" is the scripting runtime version that's Standard 2.0 compliant, and that's what you should use, but you should set the API compatibility level to Standard 2.0.
     
  8. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @Baste,

    I've had to ask myself this same question many times over the last decade or so, and I've found it's honestly one of the things I Google about Unity more than most things. For me, the simplest, most direct, generalized answer to your question is “So that I know what version to select in the top-left corner when using https://docs.microsoft.com/en-us/dotnet/api/. Perhaps there isn't a simple “it's such and such version” answer, but it would be super-useful regardless if there was a spot in the Unity Editor UI where one could see the exact .NET API & compiler versions currently in use (as well as the exact Mono/Roslyn version). You know… that old “give a man a fish vs. teach a man to fish” philosophy.