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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Future .NET Development Status

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

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    To clarify, the thread linked there is about the Linq Interpreter that is built-in to Mono's class libraries. It is not the general IL Interpreter that Xamarin uses. We don't plan to have support for the general IL interpreter on AOT platforms at this time.
     
  2. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,158
    I see. Thank you for your clarification

    But still why though? Wouldn't Linq interpreter just also use `Reflection.Emit` in the deep level and if you can use it it should also let us use general IL interpretor anyway?
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    I'm not entirely clear on the details of the Linq Interpreter, but I don't believe that it uses System.Reflection.Emit, even at the bottom level. I'm fairly sure that it works completely with Xamarin's Mono AOT on iOS, for example, without a need to fall back to a general IL interpreter.

    It does require the use of value-type generics that are not available at compile time though. Hence it needs the new IL2CPP code generation option that shipped in 2021.2 to do fully shared generics (as discussed in that thread).
     
    Thaina likes this.
  4. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    416
    So we have some update for the support for UnityNuGet and .NET Standard 2.1 in 2021.2 (and 2022.1)

    The changes required for UnityNuGet to be compatible with .NET Standard 2.1 should be working (the server is still not published) but @bdovaz found that the last bit in Unity is still not working.

    It turns out that the editor runtime assemblies are missing some of the .NET Standard 2.1 assemblies while they are on the AOT part. Folks from the VM team are working on a fix.

    In the meantime, you can try this locally in your Unity install by copying the following assemblies:

    - System.Buffers.dll
    - System.Memory.dll
    - System.Threading.Tasks.Extensions.dll


    from the folder $UNITY_INSTALL_FOLDER\Data\MonoBleedingEdge\lib\mono\unityaot-win32\Facades to the folder $UNITY_INSTALL_FOLDER\Data\MonoBleedingEdge\lib\mono\unityjit-win32\Facades
    (change -win32 accordingly to your editor platform)
     
    adamhill, Tanner555, stonstad and 6 others like this.
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Thanks to @xoofx and @bdovaz for tracking this down! The public Issue Tracker link for this bug report is: https://issuetracker.unity3d.com/is...stem-dot-memory-system-dot-buffers-at-runtime

    I'll respond on this thread with details about which versions the fix will ship in.
     
    adamhill, SugoiDev, NotaNaN and 3 others like this.
  6. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    789
    I mentioned this a month ago and should have written a bug report. I thought it was read.
    https://forum.unity.com/threads/202...donlyspan-under-net-4-8.1152104/#post-7435766
     
    xoofx likes this.
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    xoofx likes this.
  8. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    610
    I really appreciate the amount of detail you're putting into this. It doesn't go unnoticed and I hope the promise of a tight .NET integration may be fulfilled to the fullest. Framework vs Standard headaches, library integration trouble, Assembly Definition madness, and of course Mono Runtime compilation; these all have never been 'issues', but the .NET quality-of-life-improvements will make them LOOK like issues from an ancient time.
     
  9. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,158
    Do we have a roadmap of which unity version this issue would be completely fixed?
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    No, we don't yet. The fix should be completed internally today, it may be a week or so before it lands in the release branches, and then we need to see how that lines up with a public release. I'll post here when I know the version which has the fix.
     
    Tanner555, xoofx, djsell and 5 others like this.
  11. PerfidiousLeaf

    PerfidiousLeaf

    Joined:
    Aug 30, 2019
    Posts:
    20
    For transparency purposes, it should be titled ".NET Standard 2.1" in the selection menu as it makes it clear what version of .NET Standard it is. There's no harm in it and it's just visual clarity at no cost.
     
    NotaNaN and TheZombieKiller like this.
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    We have decided to make this change. Thanks for the suggestion (and to the others who suggested it). We appreciate the feedback. I'll respond here when I know which versions of Unity this will land in.
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    The Api Compatibility Level option will now be named ".NET Standard 2.1" in Unity versions 2021.2.0b15 and 2022.1.0a12 when they are released.
     
  14. aizuon

    aizuon

    Joined:
    Jun 24, 2014
    Posts:
    7
    Are there any news on when the new mono runtime and .NET Standard 2.1 builds can come to release cycle of 2021(not beta or alpha)?
     
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    We have no plans to release the new Mono runtime and .NET Standard in version 2021.1. However, everything will be in in 2021.2, which should be out of beta in the next few weeks.
     
  16. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    @JoshPeterson
    I have two small questions about possible future features:
    1. Do you have any plans to bring generational GC into Unity?
    2. Do you have any plans to update WebGL ThreadPool and Timer to work on single thread similar to how it was done in Blazor?
     
    KuraiAndras and MadeFromPolygons like this.
  17. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Hi Josh, does this upgrade in 2021.2 bring speed up to the domain reload phase?
     
  18. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    We're not sure about this yet. We're currently working on .NET 6 support in Unity. If the JIT runtime solution ends up being CoreCLR, then yes, Unity will have generational GC (most likely) with CoreCLR for JIT platforms.

    I'm not sure about this - I would ask on a WebGL specific section of the forums, as this is more up to the WebGL team than our team.
     
    Tanner555, cxode, NotaNaN and 2 others like this.
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    I don't believe there are any domain reload performance improvements in 2021.2 from Unity's side.
     
    00christian00 likes this.
  20. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    Thanks for the information!
    Any plan to bring something similar to SGen(or sgen itself) for il2cpp and mono runtimes?
     
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    No, I don't expect that Unity will use SGen as a GC solution any time soon for Mono or IL2CPP. I think it would be more likely that you would see CoreCLR GC with IL2CPP, but we have no firm plans to do that soon either.
     
    Tanner555 and VolodymyrBS like this.
  22. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    Sounds interesting, thanks;)

    will it be just UI change or willdefines for .NET Standard 2.1 be changed too?
     
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    This change is just to the UI. There is another change in progress add a C# define as well.
     
    Tanner555 and VolodymyrBS like this.
  24. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    We now have a fix ready for this issue (https://issuetracker.unity3d.com/is...stem-dot-memory-system-dot-buffers-at-runtime).

    The fix will be in 2021.2.0b16 and 2022.1.0a12 (and later versions of Unity). There are also some changes to Unity NuGet that @xoofx will update us on. With both changes, everything for .NET Standard 2.1 support should be working properly with Unity NuGet.
     
  25. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    416
    So the latest UnityNuGet version (in addition to the fix above for Unity) should provide support for both .NET Standard 2.0 and .NET Standard 2.1

    Note that If you are relying on UnityNuGet, you will have to delete the cache folders for previously downloaded packages from this registry (e.g on Windows, it is in
    %localappdata%\Unity\cache\npm\unitynuget-registry.azurewebsites.net
    )

    I haven't been able to test this latest UnityNuGet server with Unity yet, so I can't say if it is going to fully work or not, but this should be easily fixable for the remaining bits...
     
  26. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    741
    Will partial methods (C#9 feature) be added?

    This would be very helpful for me when writing client/server logic so i can split code into different scripts under a partial class to keep client and server code separate making it far more manageable and less confusing for people working on a project.

    Hope you can consider it if it is not currently supported.
     
  27. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    610
    I just wanted to make sure: do you think that source generators will one day be supported in Unity?

    A great use case for this would be to automatically prepare static fields and static event handlers for "Enter Play Mode Options". I'll need to check if it would actually work... but if it does this could be a great solution to be implemented in Unity.
     
    jasonboukheir and andreiagmu like this.
  28. Nirlah

    Nirlah

    Joined:
    May 6, 2018
    Posts:
    10
    They already work, you can go back a few pages to see how to add them...
     
    CaseyHofland likes this.
  29. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    Thanks for this topic; it's great to see progress!

    What is the value proposition of upgrading to .NET 6 and using Mono as a JIT instead of CoreCLR/RyuJIT?
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    We're currently evaluating exactly this question! I don't have anything to share now, but I will once we have more firm plans.
     
    Tanner555, cxode, Thaina and 6 others like this.
  31. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    @xoofx @JoshPeterson I have a bug report: 1373388. Tested on 2021.2.0b16.

    I don't know if the problem is on Unity side or UnityNuget side.

    Building on Android platform I get this errors:

    upload_2021-10-15_19-7-24.png
     
  32. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    @xoofx @JoshPeterson And I have another one on UWP platform: 1373389.

    I get this error:

    UnityException: Failed to run reference rewriter with command

    [...]

    Catastrophic failure while running rrw: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
    at Unity.SearchPathAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
    at Mono.Cecil.MetadataResolver.Resolve(MethodReference method)
     
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Thanks for both bug reports. We will investigate them.
     
    KuraiAndras and bdovaz like this.
  34. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    For this case 1373388 I got this answer.

    upload_2021-10-18_19-14-31.png

    I guess it is because this QA person has not been put in context of the problem and has given me this answer that has nothing to do with the problem.
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Thanks, I'll talk with the QA team about this.
     
    bdovaz likes this.
  36. Ruan_Cardoso

    Ruan_Cardoso

    Joined:
    Jul 9, 2017
    Posts:
    7
    @JoshPeterson

    The defines:

    #if NET_STANDARD_2_1
    #endif

    .Net Standard 2.1 defines not work.
    does not work in the last version of Unity(2021.2.0b16) in the editor, not tested in build.
     
  37. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    This is expected. The new C# defines have not made it into a release yet, unfortunately.
     
  38. Ruan_Cardoso

    Ruan_Cardoso

    Joined:
    Jul 9, 2017
    Posts:
    7
    Thanks to relply.....

    I found another problem, if you change the API Compatibility Level, the "defines" are defined correctly, but when going back to the old API the "defines" are not removed, they are still defined, to fix it is necessary to run "regenerate project files" on the references.

    Tested In Unity 2020 and 2021.

    Its a bug?

    I'am use Vs 2022.
     
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    That seems to be incorrect behavior. However, nothing related to .NET Standard 2.1 is in Unity 2020, so at least this is some existing behavior though. Maybe submit a bug report and we can investigate.
     
  40. Ruan_Cardoso

    Ruan_Cardoso

    Joined:
    Jul 9, 2017
    Posts:
    7
    Thanks, I did the report, can you tell me when the sets "NET_STANDARD_2_1" will be set?
     
  41. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Yes, I'll update this thread when that change is available in a Unity version.
     
    Qbit86, Tanner555, SugoiDev and 3 others like this.
  42. Gustavo-Santos

    Gustavo-Santos

    Joined:
    May 4, 2014
    Posts:
    13
    Interface default implementation is a requirement for a serializer I'm working on for unity. So I downloaded version 2021.2.0b8. And indeed, it is compatible with this feature. However I'm experiencing an error that I believe is a unity bug.
    I've made the following interfaces:
    Code (CSharp):
    1. public interface IFoo
    2. {
    3.     public void LogTypeless(object obj);
    4. }
    Code (CSharp):
    1. public interface IFoo<T> : IFoo
    2. {
    3.     void IFoo.LogTypeless(object obj)
    4.     {
    5.         Debug.Log(nameof(LogTypeless));
    6.         LogTyped((T)obj);
    7.     }
    8.  
    9.     public void LogTyped(T t);
    10. }
    Code (CSharp):
    1. public class Foo : IFoo<string>
    2. {
    3.     public void LogTyped(string t)
    4.     {
    5.         Debug.Log(nameof(LogTyped));
    6.         Debug.Log(t);
    7.     }
    8. }
    Then, if I do something like
    Code (CSharp):
    1. ((IFoo)new Foo()).LogTypeless("Hello");
    Unity breaks...
    I've tested this on a pure dotnet app, and it works as expected, outputting the following:
    LogTypeless
    LogTyped
    Hello

    @JoshPeterson could you confirm if this bug Im experiencing is something related to unity? And if yes, there is some hotfix/bugfix going on at this?
    Thanks in advance
     
    Last edited: Oct 22, 2021
  43. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Can you provide details about what happens that indicates this is a problem? Is there an error message? Or doe the code just execute incorrectly? We have corrected at least one issue related to default interface methods support recently, but I'm unsure if this is related to it.
     
  44. Gustavo-Santos

    Gustavo-Santos

    Joined:
    May 4, 2014
    Posts:
    13
    Unity editor just crashes, closes and then opens the `Unity has stopped working` window.
     
  45. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    Oh, that does not sound good. Can you submit a bug report then?

    https://unity3d.com/unity/qa/bug-reporting
     
  46. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    610
    I tried my hand at this. I got as far as getting the roslyn alayzers working, but I can't do the same for CodeAnalysis.

    This is what my Plugin Inspector looks like. Green shows what I think is right and red shows what I think is wrong.
    Img.png

    1. The plugin is not included on any platforms :D
    2. The assembly targets .NET 4.x :mad:
    3. It has a RoslynAnalyzer Asset Label :D

    How does my setup look so far? Is there anything here I should change?

    I was also confused as to what you meant with "build the project with the following config". I can find app.config and package.config, but neither file looks like the one from your example. May I ask what file I have to change?
     
  47. bruno-garcia

    bruno-garcia

    Joined:
    Nov 8, 2016
    Posts:
    7
    I'm trying the Sentry Unity package retargeted to .NET Standard 2.1 on Unity 2021.2.0b16.3733 and it fails at runtime with:

    System.TypeLoadException: VTable setup of type System.Text.Json.Utf8JsonWriter failed

    The DLLs that we bundle in the UPM package are:
    https://github.com/getsentry/unity/tree/main/Runtime

    It depends on System.Text.Json version 5.0.0. The dependencies are listed on NuGet, see target NS2.1: https://www.nuget.org/packages/Sentry/3.10.0

    I didn't get any warnings of conflicting DLLs but I wonder if Unity itself is bundling S.T.J now on a version lower than 5.0.0?
    Since it's an alpha version of Unity it's not a big concern yet, I just want to make sure it'll be compatible once the release comes out.
     
  48. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    Microsoft is finally making their own JSON instead of telling people to use Newtonsoft? Only 15 years too late.
     
  49. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    358
  50. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    789
    Is already 2 years old, (since .NET Core 3.0) and is about 2 times as fast because it uses under the surface Span<T>. Microsoft was Newtonsoft.Json too slow, but the developer did not want to break compatibility.
     
    Thaina likes this.