Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity Future .NET Development Status

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

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    I guess even just the player runtime is not yet shipped at 2023.2 right?
     
  2. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    296
    I respect you don't want to share a date. Could you instead write a few lines about the progress?

    For example:
    How's going CoreCLR intergration?
    What roadblocks you've encountered?
    Is AssemblyLoadContext working well?
    What remains to be implemented?

    I love the work you're doing, both you specifically here in this thread and you as Unity in regards to CoreCLR.
    For me it's the most exciting feature since PBR renderer.
     
    TangerineDev, JesOb and Qbit86 like this.
  3. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    358
    I think at least one of these questions will be answered in the blog post (scheduled for September, see here).
    This post also gives some information on what is going on (though it is already 1.5 months old, more work has probably been done since then).
     
  4. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Is there any plan to slowly port Unity C++ engine code to C# and even better burst compatible C# code in future after release CoreCLR?
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Correct, I can say that we are not planning to ship a Unity Standalone player with CoreCLR in 2023.2. We are planning to ship that in a future release, but which release is not yet public.

    Yes, that is a good idea!

    Excellent, actually! We've been very happy with CoreCLR as a JIT runtime. It looks like we will be able to integrate it into Unity with few or any changes from the upstream code in the dotnet/runtime repository. This is really key to our long-term strategy, as it will allow us to update to future .NET and C# versions much more quickly.

    Our biggest area of development has been around making the Unity Engine code safe for the CoreCLR GC. I wouldn't call this a roadblock, but it has not been an easy task. When this is complete though, we expect to be able to take full advantage of the increased GC performance from CoreCLR.

    Yes! Initial work on this has shown that we can use AssemblyLoadContext as a replacement for domain reload to do in-editor iteration. There is still a lot of work here to complete, as in-editor iteration is pretty complex, and touches many parts of the engine and editor code, but things look promising.

    Lots, actually. I can't probably list everything here. Certainly we have more GC safety work, as well as in-editor iteration work. We're also work on Burst/DOTS integration to make sure those technologies work with CoreCLR.

    So yes, we have already been at this for a while. I'm impressed with the progress the team has made so far (I wish I could highlight more specific of these developers, it has been amazing). But we have plenty of work ahead of us still, so no release ETAs just yet!

    And there is still a blog post scheduled for September where I will go deeper on some details. We'll see if that schedule holds, there are a number of pretty cool things happening at Unity and sometimes the blog post schedule changes to highlight other work.

    Thanks for all of the interest, honestly I cannot wait to deliver this to all of you.
     
    Trigve, cxode, Matheuz and 15 others like this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Yes, this has been going on for a while, even before the .NET Modernization initiative started. We're writing a lot of new code in C#, and I expect that to continue. There is still some C++ code going in, but much less than in the past.

    As part of the GC safety work, we're also tightening up our managed/native interop to make it easier for developers writing Unity engine code to work in both languages.
     
    Anthiese, JesOb, NotaNaN and 2 others like this.
  7. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    I'm actually curious about how you evaluate if the code is working without having migrated all the code. Because well.....you can't have part of the engine running on CoreCLR and part of it on legacy......or how does that work?
     
  8. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Can I expect zero breaking changes for dots project when switched CoreCLR since dots project enabled enter player mode options by default?

    Awesome. Hopefully can port more C++ to C# so it's much smoother to upgrade to each new .NET version release next time. And also seems like latest .NET performance is quite near or even better than C++ so less reason to C++ anymore. I would like to see the future where unity engine becomes full pure C# engine.
     
    Qbit86, CaseyHofland and Mindstyler like this.
  9. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    165
    Will Unity use the official C# Coding guidelines going forward? I've seen quite a lot of code were naming conventions were not properly used (such as lowercase property names instead of camel-cased ones)

    Also, as code is now moved to C# will you take certain actions to improve overall code quality? I have seen quite a few packages from Unity where the code quality is not up to par of what one would expect, also stuff like extensibility of the APIs come into mind.

    One of the main things, would also be unit / integration tests for the C# packages (this could alleviate breakages such as seen recently for example with the Unity IAP package on Android)
     
    Qbit86, TangerineDev and bdovaz like this.
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Good question! So currently we have internal builds where all managed code is running with CoreCLR, and most of the internal tests which touch that code are passing.

    But that code is all using a garbage collector that never collects! You can find out "NullGC" here: https://github.com/Unity-Technologies/runtime/blob/unity-main/unity/unitygc/unitygc.cpp

    So basically we just allocate until we run out of memory. The good news is that most of the tests and projects we have internally don't run out of memory until we can get useful signal that what they are testing does indeed work.

    Then we can enable the "real" GC and incrementally enable test cases that work with it over time.
     
    cxode, Matheuz, ledshok and 6 others like this.
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I would not expect zero breaking changes, but we're looking to minimize it as much as possible.
     
    cxode, Matheuz, Anthiese and 4 others like this.
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    These are all important concerns. I do believe that some of them are being addresses, but to be honest, they are orthogonal to the CoreCLR work that I'm involved in, so I don't know much about them.

    I do expect that .NET Modernization as a whole will ship without any of these concerns addressed. But they may be addressed separately via other work.
     
    cxode and bdovaz like this.
  13. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,015
    @JoshPeterson Something to say about sdk style csproj + native nuget + dotnet sdk compilation?

    Thanks!
     
  14. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    That work is also in-progress. I'm not quite sure what feature will land when and how they will look, but our overall goal is to make the C# build process more like the normal .NET build process.
     
    Matheuz, Qbit86, Laicasaane and 3 others like this.
  15. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    296
    Looking forward to that, love blog posts which go deep into the .NET. If it's anywhere close to Making AnimationEvent safe for the CoreCLR garbage collector it will be perfect.
     
    bdovaz, CaseyHofland and JoshPeterson like this.
  16. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    Please don't...

    Treat this as a breaking change, as a major release, as something that shouldn't be migrated to!
    I hate this mentality and it is literally the whole reason why we still have deprecated references to components in MonoBehaviors.

    Honestly if Unity could treat this release as a new slate, i.e. create actual breaking change (let's start with, for example, deleting every single obsolete/deprecated piece of code) that would be an achievement imo!
     
    Nad_B, cal_cal, Trigve and 23 others like this.
  17. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    Like take Godot Engine as an example...
    They are still supporting 3.x with bug fixes, security patches and try to cherry-pick certain PRs from the 4.x releases.
    But their main focus is still 4.x and they created breaking changes as they knew some old code was becoming obsolete...

    That is literally why it is called a major release! It should break stuff!
     
  18. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    Yes please. Unity would really benefit from more mentality like this. Especially with the .net migration. While not everything might break, all deprecated and overruled code should absolutely break with every major release.

    Or at least, in a 3 year cycle, which would be better adoptable even. But anything deprecated that is older than 3 years has to be completely removed.
     
  19. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    I don't mind Unity strafing from the C# Guidelines, after all they're only guidelines, but I think it would benefit the community if Unity wrote their own guidelines that package / asset store developers can follow for consistent style. It wouldn't change any of the code, but it would settle some debates.

    It would also be massively controversial so it's probably never gonna happen :D

    Personally: "Oh no, why do I say that, I like naming all my private variables as
    _myVariable
    , I'm probably gonna have to put an
    m
    in there to please the guidelines..."
     
    Alvarden and Anthiese like this.
  20. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    No i think Unity as one major .net framework should really be a good representative and go with the official guidelines.
     
    Nad_B, PassivePicasso, Qbit86 and 2 others like this.
  21. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    167
    I want Component.collider, light and friends to die out so bad :(
     
  22. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    Thats what I'm saying! XD right?
     
  23. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    You can be a good representative and not follow the official guidelines; besides there is too much code to bother with changing variables names, no company is gonna approve THAT much breaking changes over so little gain (styling?) so it's better to think realistically and suggest options that may happen one day, rather than resulting in a board of directors laughing their asses off.

    It reads bad over text and with my sirius profile pic but I meant it jokingly :p bottomline I don't see Unity changing their style, that would be a world of pain.
     
    OndrejP and Saniell like this.
  24. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    Actually, even tho you said it jokingly, since some months ago there have already been official threads regarding code style changes.
     
  25. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    I think the main idea was that Unity from now on should adhere to some guidelines.
    This way new code will be stylistically correct as well as easier to read! (And old code hopefully removed/deprecated)

    I agree that we shouldn't really care about this as much as we are currently, especially because Unity is starting to do exactly that!

    I agree 100%! The main purpose of a naming convention is that it is some kind of guideline, that indicates for example the access modifier of a variable and not necessarily be stylistically "beautiful", but rather quick to read!
     
    CaseyHofland and bdovaz like this.
  26. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    How promising exactly?

    The thing I am most excited for, even more so than .NET 7 support, is not having to wait 10+ seconds for every domain reload T_T

    On an empty test project, how long does reloading regularly take? If it’s anywhere below 2 seconds you made a happy man.
     
    Last edited: Aug 16, 2023
  27. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    For a MUCH LONGER question, I recently read an article about why the Unity Editor can become slow, and some of the biggest culprits were, drumroll, domain reload and serialization. (Partly because of garbage collection needing to scrub for leaked data which is just… poor craftsmanship. Sins of the father.)

    If you are personally interested, I would love to get your opinion on it! But it’s a really long read and I wouldn’t expect you to.

    http://blog.s-schoener.com/2023-08-16-why-your-unity-project-is-slow/
     
    TangerineDev likes this.
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I don't have specific numbers on this, but I've asked if there are any we can share yet. Note that we might not be ready to share details about this, so the answer might just be "no".
     
    TangerineDev likes this.
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I've not read the entire post, but I know Sebastien - he has a lot of experience looking at iteration time in Unity projects, so I suspect that he provides good advice.

    The focus of our .NET Modernization project is really around two aspects of his post - script compilation and domain reload.

    For script compilation, we're going to use MSBuild to compile C# code in the Unity editor. That will allow Unity to use the same build artifacts as IDEs, and avoid the recompile when switching to the Unity window problem.

    For domain reload, we've currently planning to use "rings" of AssemblyLoadContext objects, so that changes to script code will reload separately from UnityEngine code or .NET BCL code. This will avoid the "reload the world" problem, and allow code changes to be applied much faster. One caveat here is that we are still experimenting with AssemblyLoadContext to find the right balance, so I'm not sure yet where the implementation will end up.
     
    cxode, Matheuz, WavenGD and 14 others like this.
  30. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    I expect when official improves these two aspects i.e. script compilation and domain reload, I should get zero progress bar that no more staling at editor that I can freely do coding and compile at ide and do some work at editor simultaneously and also enter play mode should be much faster than the current editor with enabled enter play mode options. The current editor is already quite fast but I expect even faster speed. Btw reload script code separately should be not just UnityEngine code and .NET BCL code but also for all the packages no matter it's official package or third party package to achieve truly incremental code compilation that only spend time compile the code that actually change. For current editor I believe it just compile and reload all code no matter what.
     
    Last edited: Aug 16, 2023
    TangerineDev likes this.
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Yeah, unfortunately we don't have any numbers to share on this yet, sorry!
     
  32. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    566
    How will MSBuild work with asmdefs? Will that still be a thing that Unity supports, or we'll have to move to modern csproj?
     
  33. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    As far as I can tell from Unity's previous mentality, they will probably have them interop together...

    But it is probably better if they created a system that automatically migrated an asmdef in a project, to their csproj equivalent and just removed the asmdef functionality altogether from the engine...
     
    Nad_B and Deleted User like this.
  34. Lhawika

    Lhawika

    Joined:
    May 27, 2015
    Posts:
    53
    I think it is stated in this very thread somewhere that they will be moving to classical csproj and msbuild in replacement to asmdef.
     
  35. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    You can watch the latest talk about the .net migration of Unity to have this answered.

    asmdefs will still exist, but silently generate a modern csproj file that will be used. That also means you can have asmdefs and 'manual' csproj's in the same project and convert them in your own time.

    (Though i would absolutely recommend to switch to the full csproj way quickly, and for Unity not to keep asmdefs around for too long)
     
    TangerineDev likes this.
  36. imblue4d

    imblue4d

    Joined:
    May 27, 2016
    Posts:
    108
    Please keep asmdefs, idc about the underlying working, just keep them for their ease of use and function

    Edit: The asmdefs could act as a front-end for csproj files if needed, but their presence contributes positively to the editor UX imo
     
    Last edited: Aug 21, 2023
  37. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Since dots is custom solution built by official I would expect zero breaking changes that official should able to upgrade the underlying core tech without pollute high level user facing API unless the API changes make it much simpler and nicer. Consider implement auto upgrader to auto upgrade most of the API and provide detailed upgrade documentation for the part that needs to upgrade manually.
     
  38. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,015
    What you are asking for is precisely the ballast Unity has had for a long time and prevents it from improving with more freedom.

    In any software that uses SemVer as Unity should have breaking changes in major versions (2022.x vs 2023.x) and document these changes.

    For requests like yours we still have from Unity 3.x the shortcuts to rigidBody etc from a MonoBehaviour.

    Having everything work without requiring development changes is very convenient from a developer point of view but this is not free for Unity, it adds a lot of technical debt.
     
  39. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    If you get into it, csproj is way simpler, cleaner, more descriptive, and consistent across .net.
     
  40. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    The "best" part is, updating unity versions always break things, just not in the code, but everywhere else xD

    Edit: well, actually, a lot of packages code does break cuz they don't have either backward nor forward compatibility.
     
    TangerineDev likes this.
  41. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    You know what you're totally right I actually forgot!
    But wouldn't it theoretically be just better if Unity forced you to change them? (Especially because there are not a lot of them, even in big projects, maybe max 100, but not more)

    Normally I would agree, but for something this simple I find that Unity should easily be able to create a simple converter between these two formats and not allow opening a project in a newer version without using this converter.

    I find that being explicit about the way that Unity is handling those files (Not converting them behind the scenes to csproj, but also creating an actual csproj and reflecting that change) is way better, don't you guys think?

    Actually interested in your opinions about this...
     
    ledshok and CaseyHofland like this.
  42. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    I would be okay with it converting behind the scenes, but with a deprecation warning at the top of asmdef files with:
    • A link to the documentation page about “how to convert”
    • A Unity version 2 years in the future when asmdefs will be removed!!! We all know Unity’s track record with deprecation so they better have some date-of-removal to which the community can hold them accountable.
     
  43. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    558
    do csproj have an equivalent of
    asmref
    ? I used them when I needed to access internals of packages without using reflection (e.g by injecting an
    [assembly: InternalsVisibleTo("MyCode")]
    in their assembly

    if not,
    asmdef
    need to stay
     
    CaseyHofland likes this.
  44. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    No csproj does not.

    There are much better ways to achieve this than asmref anyway, so asmdef should absolutely be removed.
     
  45. Deleted User

    Deleted User

    Guest

    Could you share these "much better ways to achieve this"?
     
    RunninglVlan likes this.
  46. Deleted User

    Deleted User

    Guest

    If they are converting behind the scenes, I would hope they have a button that lets you replace your asmdef with a csproj file. Like a "Replace with csproj file" button inside the warning.
     
    bdovaz and TangerineDev like this.
  47. GoshawkMachinist

    GoshawkMachinist

    Joined:
    Oct 28, 2020
    Posts:
    13
    in csproj:

    <Project>
    <ItemGroup>
    <InternalsVisibleTo Include="MyCode" />
    </ItemGroup>
    </Project>

    I'm looking forward to removing asmdefs from my projects. Hopefully this year :)
     
    Deleted User and CaseyHofland like this.
  48. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    @JoshPeterson Not completely unrelated to the upgrade, but will it become easier to use source generators? Currently there’s like 12 or so steps to get it working, none of which are particularly beginner friendly.

    https://docs.unity3d.com/Manual/roslyn-analyzers.html

    It made me hold off on source generators in a past project because time.
     
  49. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    IDK, I managed to build and test my first Source Generator in less than an hour and it included a monstrosity like this:

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. namespace Plugins.LurkingNinja.Editor
    4. {
    5.     public class OnPostProcessDll : AssetPostprocessor
    6.     {
    7.         private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
    8.             string[] movedAssets, string[] movedFromAssetPaths)
    9.         {
    10.             foreach (var path in importedAssets)
    11.             {
    12.                 if (path != "Assets/[your-path-to-your-dll]/LurkingNinja.GameUtils.Codegen.dll") continue;
    13.                 var dllImporter = AssetImporter.GetAtPath(path) as PluginImporter;
    14.                 if (dllImporter is null) continue;
    15.                 dllImporter.SetCompatibleWithEditor(false);
    16.                 dllImporter.SetCompatibleWithAnyPlatform(false);
    17.                 dllImporter.SetExcludeFromAnyPlatform("Any", true);
    18.                 dllImporter.SetExcludeFromAnyPlatform("Editor", true);
    19.                 dllImporter.SetExcludeFromAnyPlatform("Linux64", true);
    20.                 dllImporter.SetExcludeFromAnyPlatform("OSXUniversal", true);
    21.                 dllImporter.SetExcludeFromAnyPlatform("Win", true);
    22.                 dllImporter.SetExcludeFromAnyPlatform("Win64", true);
    23.                 AssetDatabase.SetLabels(AssetImporter.GetAtPath(path), new[]{"RoslynAnalyzer"});
    24.                 dllImporter.SaveAndReimport();
    25.             }
    26.         }
    27.     }
    28. }
    To be honest, I'm not familiar with importing DLLs, since I chose to do most things inside Unity so far, so if this can be simplified, someone please LMK.
    I also set a command upon build in my SourceGenerator project to copy the output DLL into the path inside my unity project, so when I switch to Unity it reimports and the above script runs. I don't really get the DllImporter API and there is no documentation. If I exclude it from ANY platform, why am I doing this per platform? Anyway. It works. And obviously I have a version in another project with multiple dll paths obviously to process more, separate modules if needed.

    ps: side note: you need Microsoft.CodeAnalysis.CSharp 3.8.0 package but despite the Unity docs, you can get away with using Microsoft.CodeAnalysis.Common 3.9.0. You will get warning because of mismatch version numbers, but it builds and more importantly it works in Unity 2023.1 (I haven't tested it in earlier).
     
    Last edited: Aug 22, 2023
  50. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    224
    You really don't need a script for this. You can also just do it manually, and since the import settings are saved in metadata, when you replace an old SourceGenerator dll with a new one, and they still have the same name, you don't need to make changes to the import settings.
     
    Kabinet13 likes this.