Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

C# 9 Support for Unity

Discussion in 'General Discussion' started by harrywyt428, Nov 11, 2020.

  1. harrywyt428

    harrywyt428

    Joined:
    Jan 30, 2020
    Posts:
    7
    C# 9 has just been released alongside with .NET 5. Will the support for C# 9 rolled out to Unity soon?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    1,723
    Probably, but...

    ...Not likely.
     
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    16,618
    Unity is typically at least one year behind the release of a new specification. C# 8 is only starting to become available with Unity 2020.2.
     
  4. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    I rather see them move to. NET 5 all together. Mono is a mess. . Net 5 is faster than il2cpp in many cases even
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    10,809
    Is .Net 5 available for all of Unity's supported platforms?
     
  6. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    They can keep the mono runtime for crap platforms ;)
     
    Petrusion, Ramobo, GliderGuy and 2 others like this.
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    10,809
    My guess is they haven't moved off Mono already specifically to avoid the mess of supporting both though.
     
    MadeFromPolygons likes this.
  8. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    941
    There is a whole thread about that here
     
    Joe-Censored likes this.
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    5,116
    We do plan to support C# 9, although we don't have any ETA for it yet.
     
  10. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    Using .NET 5 or Mono is the real question :D
     
  11. harrywyt428

    harrywyt428

    Joined:
    Jan 30, 2020
    Posts:
    7
    Yeah... Mono is a mess. I wonder would there be a massive API change if we migrate from Mono to .NET 5.
     
  12. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    NET 5 does not support app domains which unity uses to reload when you change code.
     
    Joe-Censored likes this.
  13. harrywyt428

    harrywyt428

    Joined:
    Jan 30, 2020
    Posts:
    7
    Is it a Mono-specific feature..?
     
    HoL0DoK_ likes this.
  14. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    No full framework
     
  15. harrywyt428

    harrywyt428

    Joined:
    Jan 30, 2020
    Posts:
    7
    Or if it is not available in .NET 5, are there any alternatives for Unity to recompile/reload on code changed?
     
  16. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    136
    .NET Core has collectible assemblies and it seems that .NET 5 has it too:
    https://docs.microsoft.com/en-us/do...time_Loader_AssemblyLoadContext_IsCollectible

    Collectible assemblies could theoretically improve "Domain reload situation".
    Instead of tearing down whole AppDomain and recreating it, it could be possible to just collect Script assemblies and load newer version.

    There's a lot of potential problems. First, all references to Script Assemblies and any types and their instances would have to be collected. So Unity would have to destroy and recreate objects (like it's doing now). Some objects might stay alive (like Textures...). Also all references between collected and non-collected assemblies would have to be cleaned up (e.g. subscribed events, objects stored in static fields...).

    In worst case, it should be possible to make it same as now (collect all assemblies including UnityEngine, UnityEditor, ... and reload them).

    I wonder what is being considered for Unity future, whether Mono is set in stone or whether they're considering .NET Core or .NET 5.

    EDIT:
    It seems AppDomain removal and AssemblyLoadContext are coming to Mono as well:
    https://www.mono-project.com/news/2020/08/24/native-loader-net5/
     
    Last edited: Dec 28, 2020
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    5,116
    Yes, this is being considered for the future. We've done some prototyping with CoreCLR and assembly load context as a a replacement for App Domain reloading. It is a breaking change for many projects, but it is likely something that we can work though. We don't have any specific Unity release information to share about this yet though.
     
  18. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    15
    Not gonna lie, I really need that return type covariance.
     
    MilenaRocha likes this.
  19. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    136
    It will make ICloneable and similar use cases so much better :)
     
  20. natteo

    natteo

    Joined:
    Nov 10, 2013
    Posts:
    2
    Any chance (if it is even at all possible) to just get that C# 9 pattern matching into the current C# 8 inside Unity? Or will I just have to wait till C# 9 support comes along?
     
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    5,116
    No, I don't expect us to back port a specific C# 9 feature. I do expect we will move to C# 9, but I don't have an ETA for that.
     
    Joe-Censored likes this.
  22. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    Please consider NET 5 CLR at the same time, the Mono CLR performance is way behind
     
    Tanner555 likes this.
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    5,116
    Indeed, the use of CoreCLR as a JIT runtime instead of Mono is something that we have prototyped. Again, I have no information about an ETA or release though.
     
    Tanner555, mopthrow, Ryiah and 4 others like this.
  24. timothy-eckstein

    timothy-eckstein

    Joined:
    Mar 9, 2013
    Posts:
    1
    I love having the features we do have. Thank you for all your hard work! I'm aware of the pain it is to convert a small project from Framework to Core, let alone a much larger project from Mono to Core at a low-level. So again, thank you all so much for even considering it.
     
    Ryiah, angrypenguin and hasugg like this.
  25. Kontolion

    Kontolion

    Joined:
    Feb 16, 2021
    Posts:
    1
    if c# 9 / .net 5 comes to unity, i think i'm curious the use of record type in unity, along with any other key features in there
     
    Ziplock9000 likes this.
  26. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    277
    .NET 6 Preview 1 is out
     
  27. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Ryiah likes this.
  28. stevphie123

    stevphie123

    Joined:
    Mar 24, 2021
    Posts:
    3
    Hi, when c# 9 pattern matching would be added?

    Please consider it to at least we beta test it in 2021(non-lt) version
     
  29. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    10,809
    Did you read the rest of the thread? They aren't backporting individual C# 9 features. With 2021.2 alpha already available to download, it is way too late to request any major changes like this for the 2021 cycle.

     
  30. Bonkurazu

    Bonkurazu

    Joined:
    Oct 13, 2013
    Posts:
    4
    So the thing is, C# 9 pattern matching looks like it's there?
    What's new in Unity 2021.2.0 Alpha 11 - Unity (unity3d.com)
    2021.2.0a11 changelog says they have langversion 9 and a subset of features, including "Pattern matching enhancements." I don't know if that's what you wanted.
     
  31. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    10,809
     
    Huszky likes this.
unityunity