Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity Future .NET Development Status

Discussion in 'Experimental Scripting Previews' started by JoshPeterson, Apr 13, 2021.

  1. donovanstrawhacker5

    donovanstrawhacker5

    Joined:
    May 13, 2020
    Posts:
    2
    Thr
    the UI and hotreload/compile system seems to be entirely in C#. As is the main menu and at this point a lot of the entities.
     
  2. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Has "Span" arrived?
     
    JesOb likes this.
  3. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
     
  4. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    @JoshPeterson If you can pull off .NET 6.0 without forking it, will we get an option to not bundle it with the build and require installing it separately?

    And could the player maybe become a .NET application eventually? No technical reason for it; just purity, I guess.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I doubt that this will be the case. We do plan to support .NET 6 APIs and .NET 6 runtimes, but I don't expect that to be related to how Unity players are built and packaged. Of course the build and packaging of Unity players might change separately - but we don't plan to do that as part of the .NET upgrade process.

    No, I don't expect that to happen - the Unity player will likely always remain a native executable that hosts the .NET runtime.

    Note that there is this experimental Project Tiny from Unity (https://forum.unity.com/forums/project-tiny.151/) where the player is built as a managed application though.
     
    mischa2k, phobos2077 and codestage like this.
  6. NornIndustries

    NornIndustries

    Joined:
    Jun 25, 2014
    Posts:
    5
    I've upgraded Unity to 2021.2.0b1.3029, and Visual Studio to 16.10.2, and Visual Studio Editor package to 2.0.9. Cmd also reports: .NET SDK is 5.0.301 and version 5.0.7 (NETCore 3.1.16 & 5.0.7, etc)

    Still getting: "Target runtime doesn't support default interface implementation." when I try and make a concrete function inside an interface. I must be doing something really simple wrong. Is there a config I may have missed? Or is there a problem elsewhere and 0b1.x doesn't actually have 0a21.x update?
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    No there is an open bug report for this issue: https://issuetracker.unity3d.com/issues/default-interface-implementation-error

    I'm not sure yet what the cause of the problem is, but we will investigate it.
     
    NornIndustries likes this.
  8. NornIndustries

    NornIndustries

    Joined:
    Jun 25, 2014
    Posts:
    5
  9. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    I could be wrong but it should be expected for now, isn't it?
    I mean it's still .NET 4.x and .NET Standard 2.0 only in API Compatibility Level. There no option to select .NET Standard 2.1.
    And as I understand this error is OK while there no option to choose .NET Standard 2.1 api level
     
  10. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Will .NET Standard 2.1 api level be supported in 2021.2-3 ?
     
    Tanner555 likes this.
  11. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    I mean using the "framework-dependent" model (like with .NET Framework), where players have to install the runtime instead of shipping it with and bloating the build, which isn't possible with Unity today because it uses a forked Mono and thus the official one is incompatible.

    Ideally, the official runtime would also download and cache NuGet dependencies. I can dream...
     
    Last edited: Jun 24, 2021
  12. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    phobos2077 and Ramobo like this.
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    No default interface methods should not require .NET Standard 2.1 support to work properly. So this should work now.
     
    Tanner555 and Knil like this.
  14. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, that is the current plan. I've not been able to land the changes to support it yet internally though. Once I know which release they will be in, I'll post that information here.
     
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  16. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    I'm wondering, what will happen to the old api levels? Will they be deprecated down the line in favor of .NET Standard 2.1? Personally I'd love to see only 1 supported api level in Unity eventually, even if its an older one, just for that extra layer of compatibility assurance. What is Unity's take on this?
     
    phobos2077 likes this.
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    The plan is to have only two Api Compatibility Level options, .NET Standard (which will be .NET Standard 2.1) and .NET Framework (which will be .NET Framework 4.8). We will not be keeping .NET Standard 2.0 as a separate option - we don't think this will bring any value.

    In a .NET Core-based ecosystem, we expect to have only one Api Compatibility level, but I'm not as sure about that yet. It might change.
     
    PutridEx, Ramobo, Tanner555 and 7 others like this.
  18. skyake

    skyake

    Joined:
    Jun 7, 2019
    Posts:
    11
    .NET has the ability to replace the built-in GC to a user implemented GC, which means Unity can use its own GC implementation with .NET side by side.
    See: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/garbage-collector#standalone-gc
     
    Huszky likes this.
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  21. Lhawika

    Lhawika

    Joined:
    May 27, 2015
    Posts:
    53
    I think we can understand, thank you for letting us know !
     
  22. Knil

    Knil

    Joined:
    Nov 13, 2013
    Posts:
    66
    Any word on updating Roslyn for source generators?
     
    jasonboukheir likes this.
  23. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    From my experiments it's possible to build dll with generator and insert it in project that target Unity 2021.2 as analyzer and it's just work.
    But it need to target Microsoft.CodeAnalysis.* version 3.8.0
     
  24. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, Unity 2021.2 includes Roslyn that compiles C# 9 code, so source generators should work.

    Note that our .NET runtimes do not have support for C# 9 features (e.g. covariant return types), so you will only get the compiler features.
     
    mrwellman_work and jasonboukheir like this.
  25. marce155

    marce155

    Joined:
    Jun 8, 2014
    Posts:
    8
    @JoshPeterson I'd just like to thank you for creating this thread, updating it regularly and openly communicating what your team is considering to do and what you are currently working on. We realize it's extra effort and I'd like you to know it is appreciated.
     
    Wattosan, oxysofts, Ofx360 and 21 others like this.
  26. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    Is .Net Standard 2.1 targetting still gonna be added to 2021.2 now that it's already in beta (which means that in general only bugfixes, not new features are added)? The editor is already happy to load .Net Standard 2.1 assemblies when set to targetting .Net Framework (in .Net Standard mode it errors out saying that the assembly has a higher target framework) so I believe it wouldn't be much work other that changing the reference assemblies.
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, we're planning to still get support for .NET Standard 2.1 in 2021.2. I'll mention here when I know which version will have it.
     
    Anthiese, NotaNaN, Tanner555 and 6 others like this.
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    .NET Standard 2.1 support will be available in Unity 2022.1.0a3!

    It will also be available in a 2021.2 beta release. I'll update here when I know the version.
     
    Anthiese, Laicasaane, deithl and 15 others like this.
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Note that this includes actual default interface methods support, as well as full support for C# 8 also.
     
  30. djsell

    djsell

    Joined:
    Aug 29, 2013
    Posts:
    77
    Do you know if Burst will have support for Span<T> as well?

    Last I tried to use it with including System.Buffers.dll, burst failed to compile.
     
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, Burst should work with Span<T> out of the box once this Unity version with .NET Standard 2.1 support is published. We don't yet have Span intrinsics implemented in Burst, so the code will not be as fast as possible, but that support is planned soon (although I don't have an ETA for that yet).
     
  32. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    Are any C#9 features that require runtime support supported? For example function pointers with unmanaged calling convention.
     
  33. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    266
    Those require the presence of some types in the S.R.CompilerServices namespace (eg, CallConvCdecl) which aren't part of .NET Standard 2.1, so they're not likely to be supported until Unity supports .NET 5 or 6. You might be able to manually define the types though (they're all empty classes).
     
  34. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    We don't have any runtime support for C# 9 features yet, so, for example, covariant return types will not work.
     
  35. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    When will the alpha builds be available to download and try out?
     
  36. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I expect they will be available within the next week. Although I'm a bit disconnected from the release cycle, so I'm not entirely sure.
     
    phobos2077 and TheZombieKiller like this.
  37. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    I've been wondering, are there any plans for after .NET Standard 2.1 is implemented? There has been a lot of talk and speculation about switching over to CoreCRL, upgrading to .NET 6, even rumors of hot reloading have been spread around, but are any of these points (coming) on the "Team Josh" agenda?
     
  38. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, we plan to move to a .NET Core-based ecosystem, away from a .NET Framework-based ecosystem. This will probably include .NET 6 support, although the specific .NET version we will target when this is released is still up in the air.

    We're also unsure about what the JIT runtime will be - CoreCLR or Mono.

    Finally, it looks like .NET 6 hot reloading does not include everything that Unity needs to support the current "enter play mode" workflows, but we have been in discussions with Microsoft about changing the feature to add more support. So we'll see where that goes.

    Our team's big recent development push has been to get the .NET Standard 2.1 support out - hopefully that will provide many of the newer APIs that are useful for users. We have a few loose ends to tie up here as well.

    You can see there are a lot of outstanding questions and uncertainties about a .NET Core ecosystem transition. I expect in the next month or so our team will shift into a research mode for a bit to answer these questions (I think we now at least know all of the questions that we need to answer!). So I expect the announcements for future .NET features will slow down a bit, but we are planning to continue to move forward.
     
    NavidK0, pvloon, Anthiese and 20 others like this.
  39. Huszky

    Huszky

    Joined:
    Mar 25, 2018
    Posts:
    109
    Any update on using the standard .NET project system / build tools? It would be really beneficial if the csprojs would not be auto generated and we could have NuGet support, referencing csprojs outside of unity, and finally stop checking DLLs into version control?
     
  40. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I don't have any update on this. I don't think that it is on the near-term roadmap, but maybe @xoofx can provide more information.
     
  41. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    266
    I currently use a dummy csproj that copies the .dll and .xml files into the Unity project on build. It's a lot more convenient than manually downloading all the dependencies, allows me to avoid checking binaries into my repository, and avoids (most of) the weird edge-case issues that can crop up with the third party NuGet integration plugins I've tried before. I just went ahead and published it all here for anyone interested.

    I should also mention that if a package references something that is already included (and thus results in errors within Unity), you can add it explicitly and then use ExcludeAssets="all" to prevent it from being copied into the project:
    Code (xml):
    1. <PackageReference Include="System.Numerics.Vectors" Version="4.5.0" ExcludeAssets="all" />
     
    Last edited: Jul 23, 2021
    jasonboukheir and Huszky like this.
  42. Huszky

    Huszky

    Joined:
    Mar 25, 2018
    Posts:
    109
    I have also made several solutions to this:
    (Newer solution) https://github.com/KuraiAndras/CsprojToAsmdef
    (Older) https://github.com/KuraiAndras/UnityCsprojNuget

    I was recently tasked with creating internal documentation on among other things, what options are to using NuGet packages in Unity. I mean I get why it is not a high priority issue for Unity, but honestly It just bogles my mind that when some .NET developer wants to use NuGet packages as they used to, they have to spend days of fiddling just to get it somewhat right (neither of my solutions work the way a sane project setup would work).
     
  43. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    This one ain’t mine so I can’t tell you too much about it, but for someone who isn’t really well-versed in all the compiler behind-the-scenes, this solution was really easy for me. https://github.com/GlitchEnzo/NuGetForUnity

    It basically adds a NuGet package manager into Unity that handles the rest. I don’t know if it’s a complete solution to all the things described above, but I have been happy with its NuGet handling at least.
     
  44. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I've just learned that .NET Standard 2.1 and default interface methods support will be available in 2021.2b6.
     
  45. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    I finally measured the difference between
    old mono fork
    and
    new mono fork
    with that project I used for years to report performance regressions to Unity.

    New mono fork is faster with this project. Below are the results and how the test works is explained here.

    scene_4_3.png

    scene_5_4.png

    scene_6_8.png
     
    Last edited: Aug 1, 2021
  46. Refeas

    Refeas

    Joined:
    Nov 8, 2016
    Posts:
    192
    @Peter77 You are comparing a17 vs b5, could that difference just be that b5 is more polished/fixed up?
     
    JesOb likes this.
  47. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    I would be more curious for a comparison of a version running the old .NET RT vs the new one *both* on .NET 4 :)
     
  48. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    @Peter77 The .Net 4.x/.Net Standard 2.0 setting only changes the target framework the dlls have, the runtime used for both is the same.
     
  49. Lymdun

    Lymdun

    Joined:
    Jan 1, 2017
    Posts:
    46
    To be exact, the comparaison there is not .NET 4/.NET Standard 2.0, but instead old Mono fork from 2018 vs updated Mono
     
    NotaNaN, Peter77, JesOb and 1 other person like this.
  50. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    You're right, thank you for pointing it out. I've corrected my post.
     
    FernandoMK, JesOb, MartinTilo and 2 others like this.