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. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721

    I wasn't suggesting we ditch the C# for C++ but having both would be nice. Godot for example has a variety of choices.
     
  2. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    219
    Accessing and moving things around between C++ land and C# land so it can be consumed by user code has a lot of considerations and even some non trivial performance issues. That's one of the reasons behind the effort to "bring" part of the engine from C++ to C# (along with ease of use ofc).

    Supporting multiple languages directly in an engine is usually a poor idea that ends with divided engine resources, incompatibilities, feature disparity, divided documentation, etc, etc, etc. As for C++ in particular, you can write native plugins and just add the dll to unity. Ofc u will need to write C# wrappers but code generators should help make it semi automatically (?)
     
  3. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    We just going to pretend this doesn't already happen in Unity often more frequently than in UE and Godot ? lol
     
    goncalo-vasconcelos likes this.
  4. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    62
    The issue here is that IL2CPP is pretty much terrible at generating C++, it generates code so bad that even LLVM gives up on optimizing it from what I've seen. So in fact, when we get CoreCLR, it'll most likely have much better performance than IL2CPP.
     
  5. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    I use IL2CPP so people don't easily dotpeek all my source code. Even if some one very determined can with IL2CPP it is a lot of effort that most won't try.
     
  6. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,049
    That's add a whole lot far more amount of work to do for unity
     
  7. XJDHDR

    XJDHDR

    Joined:
    Mar 31, 2020
    Posts:
    19
    Last year, I adopted and updated a benchmarking suite which compares the performance of Unity's various compilation methods against C++ and CoreCLR in various benchmarks. You can find it here: https://github.com/XJDHDR/BurstBenchmarks/tree/master/benchmark_results_2022-10-20

    My opinion overall is that, while there are 1 or 2 scenarios where C++ is beneficial, CoreCLR for the most part is either on par with C++ or not much worse. And for performance critical scenarios where you do need more, Burst and C++ DLLs can give you that.
    And I was disappointed with IL2CPP. There were 2 benchmarks where it didn't appear to compile properly, and only showed a consistent advantage against Mono in the other cases.
     
  8. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    Many tools/modules are only available in Unity as C#, e.g. ECS, Cinemachine, HDRP, URP, practically almost all packets installed via the packet manager. Either Unity would have to implement everything again in C++, or doing without access to these modules in C++ scripting.
     
  9. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    I think it was also mentioned several times by Unity staff that IL2CPP was never intended for performance, only for platforms that don't allow JIT apps.
    I recently heard somewhere in a video that even with NativeAOT there is no increase in runtime performance, but in some cases it can even be worse than the JIT version. However, the startup time is accelerated enormously and the build size is extremely reduced. Use case here are cloud applications that are only started when needed.
     
  10. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    I know I shouldn’t respond to this… ah what the heck.

    I have actually been quite impressed with Unity’s ability to coordinate a bunch of different teams into consistently designing component based packages with well written documentation. It’s no accident, you can find their style guide online, as well as a documentation on how to document packages and they’re pretty in-depth.

    By its component based design most packages already work together, and if they don’t it’s not hard to read the documentation and add the functionality you’re looking for. The urp and hdrp are unfortunate… everything else I never had a problem feature parity wise.

    Then there’s performance but I’m not fighting you on that, that’s been discussed enough.
     
  11. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    765
    There was a time when Unity supported javascript (unityscript) and python (Boo). Supporting multiple languages was apparently a lot of work on the devs and wasn't much benefit. By dropping those, the devs were able to spend more time on more valuable features and drop some tech debt.

    I seriously doubt Unity would go back to supporting multiple languages given that history.
     
    TangerineDev likes this.
  12. Xavier78

    Xavier78

    Joined:
    Oct 13, 2013
    Posts:
    40
    I have started to passive-aggressively write "//Dang you Unity!" at ever spot in my code that I am having to do unity specific C# things because it is so outdated now... there are a lot of those in my code.
     
  13. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Moving more code from C++ to C# can actually improve overall system performance by reducing the number of hops from managed to native code. Better inlining, less marshaling.
     
  14. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,043
    This might be theoretically true. But won't pan out that way.
     
  15. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,043
    Have you read any of the The New Input System documentation? It's exactly as poorly written as the schemes of usage were designed. The Animator Controller's documentation is legendarily poorly written. The docs on just about everything to do with UGUI are horrendous. Nothing to do with the TextMeshPro documentation got much ported or updated from the original website of the founders. The wordings for the low level stuff are so obtuse as to defy maze like thinking about poor writing, and most of the features aren't documented, at all.

    And that's before we get to the fragmentation that's going on with three UI systems, three animation systems, two input systems, no certain lighting systems, three rendering systems, two post processing systems, package versioning stepping and aliasing, there not being change logs in the package manager, etc etc.

    There doesn't seem to be someone in charge of how Unity should come to be, a product manager or CTO with his hands on the wheel, and there's nothing like that for individual packages in terms of how they're communicated or feature developed. It's sort of "ohhh... we should do this now... maybe..." and then we, the users, wait.

    By now, given the 5+ years to get close to having ECS and DOTS as a whole being seemingly another 5 years off, it might be time to consider open sourcing everything and figuring out how to let users see if they can wrangle performance out of Unity, by themselves, or dropping source access pricing to something attainable by individuals and small teams.
     
    Reahreic, cxode, Protagonist and 4 others like this.
  16. tannergooding

    tannergooding

    Joined:
    Jun 29, 2021
    Posts:
    16
    This does actually pan out and is covered in many of the perf blog posts we (the .NET team) release each year as the source of multiple performance gains.

    C#/.NET code is not somehow inherently slower or worse performing. There are cases where the .NET JIT/AOT produce better code than the C++ compilers and there are inverse cases as well. They end up balancing out for the most part with each having their own strengths and weaknesses in various workloads.

    There are many factors that contribute to this including not only reduced number of GC transitions, but also in being able to light up newer instruction sets that better take advantage of the underlying hardware.

    A typically C/C++ app, by default, targets the same 2004 baseline that is the original x64 CPU. It has SSE/SSE2 and the baseline instruction set. Some operating systems require a couple additional instructions like CMPXCHG16B or other systems oriented instructions like LAHF/SAHF.

    This, by default, excludes the ability to use SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, FMA, BMI1, BMI2, and all of AVX512, among others. C/C++ can of course still use those, but they require an actual check to occur at runtime in the main execution path of the code or another form of dynamic dispatch. This ultimately impacts binary size, the ease of which you can deploy your binaries (they are no longer simply portable). It can also impact perf due to an inability to inline across various compilation boundaries and the cost of otherwise hoisting those checks to take advantage of one off instructions, particularly like `shlx`, `shrx`, `mulx`, and others which are more flexible and faster versions of their baseline counterparts.
     
    oscarAbraham, cxode, bdovaz and 5 others like this.
  17. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    Unity has always been pretty clear on which packages they recommend. And besides, between fragmentation and backwards compatibility I feel they make the right choice replacing features one by one.

    I have been very happy with the documentation but that’s subjective.

    I DO agree that the Input System and anything it touches is a complete and utter mess, it needs a complete uproots rewrite but their github only shows they’re working on ANOTHER method of implementation :(
     
    Unifikation likes this.
  18. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,043
    I'm not arguing with the theory, nor the work that's going into modern C#, nor the power and precision and performance of low level C#, which is (quite frankly) amazing. And I love it. But we're talking about how Unity would use these features, or obscure them, in their goals. And within the context of their current systems and approaches. Which are parallel to the benefits of modern C# rather than exploitive of them. I whole heartedly agree with the many threads and request for Unity to modernise around modern C# and to listen to and learn from Microsoft's enormous endeavours in modernising, opening up threading and providing low level performance gains, and core affinity controls. All wonderful stuff. If you're on any part of this processes, please keep up the great work! And, THANK YOU!!!
     
    TangerineDev likes this.
  19. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    62
    Speaking of CPU architectures, @JoshPeterson will we get an option to have IL2CPP generate separate GameAssembly.dll for various sets of instructions that are supported by the CPU like Burst already can with this?
    upload_2023-6-2_21-44-20.png
    This would be useful to have once we get all the intrinsics from CoreCLR available to use in non-Burst code, without such option we'd only be restricted to baseline ones. (CoreCLR will also bring AVX512 support so this list would need to be extended)
     
    Unifikation likes this.
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    We're not planning to make this change available with the new .NET support in IL2CPP. But this is something we have one the radar for future improvements.
     
    TangerineDev, PetrisPeper and bdovaz like this.
  21. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    62
    FYI kunalspathak from the dotnet JIT team told me they'd be interested in adding the IL2CPP tool to the dotnet/runtime SPMI infrastructure that's responsible for tracking the JIT performance and codegen generated by it. If your team would be interested in doing so, you can make an issue here and tag him there. (The code wouldn't need to be made public for it.)
     
    oscarAbraham likes this.
  22. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Thanks, we will look into it!
     
    oscarAbraham likes this.
  23. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    165
    I think we should talk more about Il2cpp not compiling properly. I have unfortunately also seen wrong results when compiling more advanced C# code using lambdas and generics, Linq and Tasks, resulting in memory corruptions or invalid cast exceptions etc.
    I hope with the .Net Core Update a new deeper look into Il2cpp will happen to fix those bugs.
     
  24. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    Come to think of it… not a completely unrelated question to ask: the year is 2033 and Unity updates the .NET runtime every new release and uses the CoreCLR and Native AOT to build. In this hypothetical where Unity does not need to maintain any part of it, how will it free up the development team to do more exciting stuff with Unity, and what areas would then be focussed on?
     
  25. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    566
    Yes! I found that even a simple static constructor in a struct doesn't run in IL2CPP...
     
  26. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    Regular coreCLR updates must also be maintained, one must not forget that unity also has its own unity specific code in the runtime, and also all the communication between the C++ engine and the hosted .NET assemblies
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Please submit bug reports for any incorrect compilation or behavior with IL2CPP.

    https://unity.com/releases/editor/qa/bug-reporting

    We don't have any known serious bugs now for IL2CPP (there are a few minor ones that we work on as we can). But anything like a miss compilation or incorrect behavior will be fixed and released in back ports as soon as we can.
     
    RaventurnPatrick likes this.
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Please provide us with a bug report about this.

    https://unity.com/releases/editor/qa/bug-reporting

    This is not a known issue - static constructors work properly in all of our known tests cases, but we might be missing some cases.
     
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    This is indeed our long term goal. We plan to _not_ maintain a fork of the dotnet/runtime repository in the steady state. This will allow us to more easily update to future .NET versions as they are released by Microsoft.

    Much of the current work the team is doing now is about reducing the coupling Unity has with .NET internally and removing complexity around the integration.
     
    oscarAbraham, cxode, Qbit86 and 7 others like this.
  30. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    62
    Would this include Unity contributing missing features from IL2CPP like generic sharing into NativeAOT?
     
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    In general yes, we want to contribute as much as we can to the dotnet/runtime repository.

    For this feature specifically, we've not investigated the possibility. I suspect that the internal implementation is pretty different between IL2CPP and NativeAOT, but we would need to check into that.
     
    oscarAbraham, bdovaz, Zarbuz and 5 others like this.
  32. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    566
    I did, it's CASE IN-43207.
     
    JoshPeterson likes this.
  33. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,015
    I think the last update was this one at the end of April.

    Can you tell us something new? In my case it is more curiosity because I find interesting all this adventure in which you have embarked with the many challenges it involves.

    Thanks @JoshPeterson!
     
  34. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    This silence could mean positive or negative things...
    @JoshPeterson please give us some insight!
     
    bdovaz and Unifikation like this.
  35. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    Unity just recently had a bunch of mass layoffs - it's possible things slowed down a bit. Depending which teams got gutted.
     
    TangerineDev and Unifikation like this.
  36. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,043
    The best we can hope for is some polish to existing systems.

    Newness probably on hold throughout the organisation - as it's hard to justify and quantify.

    Sadly, the layoffs you speak of were the third, creating a pattern that aligns with statements by their leader that more are to come.

    Combined, this means that everyone needing their job at Unity has probably gone into various forms of bureaucratic arse covering, rationalisations, record keeping and justifications for their survival, whilst othering those they'd prefer to see gone. Those others are often the best risk takers, and more capable, and inclined, able and likely to be consciously packing their bags and looking for greener pastures.

    A pattern as old as time in corporations going down this phase of merger and acquisition staff cleanups is all subsequent creativity and growth can, thereafter, only ever come from ever more acquisitions.
     
  37. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    Wow, das pretty sadge-

    Josh has already responded that no one of his team was affected by the layoffs, dude's probably either busy or on vacation, the question is not a week old. It's odd because he usually has quick response time but to couple this to the layoffs is a bit dramatic I think.

    That being said, I too do not understand how leader of "voted worst company twice in a row" got given the keys to the Unity kingdom, but that's neither here nor there.
     
  38. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Is there any plan to migrate more C++ code to C# land and burst it?
     
  39. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    122
    For sure! How do you think so many packages keep popping up? But I don't expect them to migrate engine critical code, like multithreading, physics, (although a good chunk of that also was migrated => Havok, also the rendering pipeline).
     
  40. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Hey, so I should give an update! My comparative silence is not due to a lack of stuff happening, in fact there is lots going on with this project, and we have been pretty busy (but most of it is pretty internal now so there had not been much news to share and in fact I was out of the office last week :) @CaseyHofland).

    Our current effort is very much focused on making the Unity C++ engine code safe for the CoreCLR GC. We have a development blog post planned for a few months from now with some details, but I can fill in a bit now.

    After 15+ years of engine development, there are thousands of places in the Unity C++ code which assume the GC will not move managed objects. We're finding and fixing all of those! This is a large task, and we've been at it in earnest for a few months now. We're starting to see the end of the road, and so we are getting pretty excited.

    In addition to GC safety, we are also ramping up work now on MSBuild support for C# compilation, editor code reload replacement for domain reloads, and IL2CPP support for the CoreCLR BCL. Basically we're following the roadmap we have discussed publicly in the GDC and .NET Conf talks I've done.

    Regarding resourcing, we're had great support from upper management for this project, so we have plenty of excellent developers actively engaged. From my end of things, the most difficult part is lining up work fast enough!

    Hopefully this provides some comfort - I wish that we could deliver this sooner, but there is a lot of work! We're operating at a fast pace, and making internal progress. I'm excited to share more externally when I can.
     
  41. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,015
    Great job @JoshPeterson (and the rest of the team)! I'm sure you are suffering with the technical debt but learning a ton along the way.

    Edit: On the part of Microsoft in these last months I am reading very interesting articles about the challenges they are facing to migrate complex services from .NET Framework to .NET 6:

    https://devblogs.microsoft.com/dotnet/tag/migration/

    In case it inspires you to see that you are not the only ones embarked in this type of adventures!
     
  42. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I would not call it suffering at all! The work is challenging, but also rewarding. Indeed, the assumptions made in the Unity C++ engine code are absolutely valid for the time the code was written. We are now changing the rules of the game, with a better future in view.

    As multiple developers working on the project have observed, the code is always better and more readable after making it GC safe. So we have both extrinsic (making a better product to deliver to you all) and intrinsic (improving the code itself) motivations. In my experience, those combining leads to a happy and productive team, which is what we are after!
     
  43. gui_brawl

    gui_brawl

    Joined:
    Sep 2, 2020
    Posts:
    3
    @JoshPeterson this is very nice to hear.

    I totally respect the "silence" and the small amount of detail you give us in each update. This is the type of project that is impossible to predict, be it the deadline or the amount of resources that can be completed in a timely manner. So it's better to be safe and create a polished product than to rush and disappoint the user base.

    But I'm very curious. This looks like a very difficult project to pull off, and I'll be happy to hear the details! So, please, when everything is ready, write a post here (and on the dotnet blog too) telling all the details about this migration. It will certainly be very fun and enlightening to read about the technical challenges.
     
  44. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    It is! But we're having fun doing it. :)

    We have a Unity development blog post scheduled to be release in September with some of the details you are looking for. The post is not yet written, so I appreciate the input. I'll try to go into as much detail as I can, and hopefully have an engaging post.
     
  45. Rafaedsb

    Rafaedsb

    Joined:
    Jan 5, 2020
    Posts:
    2
    @JoshPeterson, do you think we will have these changes in which alpha version? 2023.3 or 2024.1?
     
  46. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I can't yet say when the new .NET work will be available, sorry!
     
  47. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    165
    There are a few upcoming events such as the Unity Unite 2023 (November 15-16) and also next years GDC (18 March 2024) - I would expect a roadmap to be revealed at such events (of course as long as it is ready).
    Personally I would not expect .Net Core features to be available before Unity 2025
     
    Deleted User likes this.
  48. HippyJesus

    HippyJesus

    Joined:
    Dec 2, 2020
    Posts:
    8
    Please be as tech nerdy as possible when you do write it up! I for one am fascinated by how much legacy stuff you will have to update to pull this off and would love to know as much as you can reveal about the nuts and bolts of it all.
     
  49. OldPocketWatch

    OldPocketWatch

    Joined:
    Jun 16, 2021
    Posts:
    7
    Rome wasn’t built in a day, I see, but on the other hand does it mean that we can't expect new .NET work be published in one or two years?
    Coding would be very different between Mono and CoreCLR, lots of code writen now may not be necessary when new .NET features are introduced. It would be awkward for me if I put in a lot of effort in "c#9 style" coding, and then Unity suddenly adopts .NET 8 or even 9. Not urging, just wonder.
     
  50. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    548
    What redundancy are you facing exactly? A lot of people here may be able to help you with how to best approach it, but it’s on a case per case basis.