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. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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,938
    We would love to get there, but I don't think we can reach that initially for most projects. There is a lot of performance analysis and improvements we need to still do internally though, so I'm not ready to make a definitive statement yet.

    Yes, we're hoping to support that feature. We don't have all of the pieces in place to do that yet, but it is on the plan.
     
    Nad_B, SamOld and JesOb like this.
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I think you analysis is correct. The in-editor code will need to change significantly to work with this new paradigm. Our goal is to make that transition as small and simple as possible. We're not far enough along yet to know exactly how that will look, but there is a lot of code within Unity that we need to change to make it work, so we should have some good experience to help blaze a trail for changes like this.
     
    479813005, Xtro, Nad_B and 1 other person like this.
  3. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    612
    Thank you very much for everything Josh. I already started transitioning to "no domain reload" feature for 2 reasons. 1) It will be mandatory in the future anyways, 2) Scene based editor tests via TestRunner I want to implement requires disabling domain reload (this is the reason I started the entire topic).

    Knowing the reasons why you are going this way gave me clarity, making it easier for me to concentrate on the transition. Thank you.
     
  4. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    71
    My whimsical thoughts.

    Let's make it optional to reset static variables.

    Each time you enter PlayMode, a dialog box pops up asking if you want to reset a static member.

    Add two more Settings, whether the inquiry dialog box should pop up every time you enter PlayMode, and whether the default behavior is to reset static members if you do not ask.

    Or multiple Play buttons.

    More Settings, more humanity.
     
    Thygrrr likes this.
  5. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    560
    I think there is an XY Problem here.

    you don't want to "reset statics", you want to ensure references are still valid in play mode.

    so while this is bad:
    Code (CSharp):
    1. class Whiskey : MonoBehaviour {
    2.   static Instance;
    3.   static Whiskey() {
    4.     Instance = FindOrCreateGameObject("...").GetOrAddComponent<Whiskey>();
    5.   }
    6. ...
    7. }
    these are completely fine:
    1)
    Code (CSharp):
    1. class Whiskey : MonoBehaviour {
    2.   static _instance;
    3.   static Instance {
    4.     get {
    5.       if (!_instance) _instance = FindOrCreateGameObject("...").GetOrAddComponent<Whiskey>();
    6.       return _instance;
    7.     }
    8.   }
    9. ...
    10. }
    2)
    Code (CSharp):
    1. class Whiskey { // no touching scene
    2.   static Instance;
    3.   static Whiskey() {
    4.     Instance = new Whiskey();
    5.   }
    6. ...
    7. }
    3)
    Code (CSharp):
    1. class Whiskey : MonoBehaviour {
    2.   static Instance;
    3.   static Whiskey() {
    4.     UnityEvents.EnterPlayMode += () =>
    5.         Instance = FindOrCreateGameObject("...").GetOrAddComponent<Whiskey>();
    6.   }
    7. ...
    8. }
    (note: pseudocode, actual APIs may differ)


    also, I think there are 2 separate concerns here:
    1) domain reload on script change => will be replaced by ALC, code is reset but may require cooperation to shut off properly (e.g. threads? cross-asm references?)
    2) domain reload on enter play mode => can be disabled now, code is not reset bit there are plenty of replacements
     
  6. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    705
    I mean, there's a solid third party hot reload package available that even works with Burst. If a small 3rd party team can come up with it, how hard can it be?

    I think the move to CLR should be prioritized above literally any non-fix additions to the code base.

    And please bury IL2CPP, it has overstayed it's welcome. (If you ask me, even get rid of Burst but that is a slightly more nouanced discussion, IL2CPP is basically harkening back from the ASM.js days).

    Replace it with .NET AoT compilation. That's the definitive future which has on the day of its release driven all custom solutions into instantaneous obsolescence.
     
    Last edited: Nov 28, 2023
    PanthenEye and Nad_B like this.
  7. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    306


    Here's some talking of the .NET modernization work at Unite. (around 59:06)
     
    Eclextic likes this.
  8. Huszky

    Huszky

    Joined:
    Mar 25, 2018
    Posts:
    109
    Altough I would love to for get about il2cpp, NativeAOT does not support consoles right now, which is a dealbreaker for unity
     
    DragonCoder likes this.
  9. skyake

    skyake

    Joined:
    Jun 7, 2019
    Posts:
    11
    NativeAOT has community port that supports consoles.
     
  10. Huszky

    Huszky

    Joined:
    Mar 25, 2018
    Posts:
    109
    Can you share these projects?
     
  11. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    250
    We found that unloading statics manually mostly "works" - but as expected many hard to find/debug bugs remain due to plugins that are being used or even code that was not written with this in mind.

    As a small example: DOTween creates an instance in the "Don't destroy on load" method but never checks if this instance still exists. Thus the instance breaks and any calls to DOTween are ignored (default behavior of the plugin is to swallow exceptions) - This is just one bug but it still took us a few dev-hours to find - as it resulted in UI animations not working anymore. (and many more subtle bugs)
     
    Eclextic and Matheuz like this.
  12. rdjadu

    rdjadu

    Joined:
    May 9, 2022
    Posts:
    117
    I think that one's a good example of one way the requirements for a Unity feature differs from that of an asset store package. Our team has been using Hot Reload for a couple weeks now on our current project and all of us ended up ditching it due to how unreliable it is. It's a neat asset store package. As a Unity feature, I'd be rather annoyed with it.

    It can patch some method changes here and there, saving a domain reload every now and then. But then it has to trigger a reload on a host of other changes meaning you're never sure what you get. Plus, in our experience, many times it simply fails to reload when it needs to. On top, debugging becomes a mess with Rider getting increasingly out of sync with the actual code -- and you have to force a reload manually.
     
    DragonCoder likes this.
  13. Matheuz

    Matheuz

    Joined:
    Aug 27, 2014
    Posts:
    30
    We use DOTween extensively and that's sad to hear. I expect these plugins to adapt to it as well, but I wonder how long it would take.
     
    Eclextic likes this.
  14. Eclextic

    Eclextic

    Joined:
    Sep 28, 2020
    Posts:
    142
    Yeah, for me as well...
    I ended up turning off DOTween because I use it FKN EXTEEEEEEENSIVILY in my project and the fast play mode just doesn't work using it....
     
  15. skyake

    skyake

    Joined:
    Jun 7, 2019
    Posts:
    11
    Huszky and Thaina like this.
  16. AliAlbarrak

    AliAlbarrak

    Joined:
    Jan 24, 2018
    Posts:
    15
    Are you guys on latest DOTween version. We had issues with fast enter play mode previously but they have been fixed since v1.2.632

    I don't remember when this was released but we haven't had any issues in looong time. If you use DOTween that extensively then I recommend you to keep up with their updates as they fix bugs very regularly
     
    Last edited: Nov 30, 2023
  17. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    Weird, as I never had any problem with DOTween and Fast Play, maybe because I always keep "Reload Scene" checked, since it's fast and gives me a clean slate.
     
    Last edited: Nov 30, 2023
  18. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    250
    Thats a good point, we never updated DOTween in a few years (it was off my radar as it's not in the package manager)
     
  19. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    And apparently there's a new player in town, and it seems to be even better than DOTween in functionality and performance (zero allocations)

    https://github.com/KyryloKuzyk/PrimeTween

    Will give it a try in my next project.
     
    KyryloKuzyk, Xtro, Alvarden and 2 others like this.
  20. Eclextic

    Eclextic

    Joined:
    Sep 28, 2020
    Posts:
    142
    Well their API from the outside looks like a 1 to 1 copy of DOTween funnily enough...
    But they do seem to support async/await out of the box! (Unlike DOTween requiring a `WaitForCompletionAsync()`...)
    Very cool! Thx!
     
    KyryloKuzyk, Thaina and Nad_B like this.
  21. Eclextic

    Eclextic

    Joined:
    Sep 28, 2020
    Posts:
    142
    That release definitely fixes the major issues (I updated it a long time ago), but some other bugs seem to come from either Unity or DOTween and I don't have the will to isolate the issue and file a bug report...

    (One for example, is that UI elements once randomly became set with the NaN values (https://issuetracker.unity3d.com/is...nd-all-the-rect-transform-fields-are-set-to-0) and it's a won't fix...

    Another is that spawning recycled DOTweens seems to not reset them correctly before using them. (Animation become broken for no reason), which is why I had to initialize all DOTweens at the start of the project to a variable and reuse that variable, instead of "creating" a new DOTween. (Which is a good performance practice, but like this is supposed to be a feature...)
     
  22. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,130
    Hi. Is http/2 supported now when unity upgrade to CoreCLR?
     
  23. Huszky

    Huszky

    Joined:
    Mar 25, 2018
    Posts:
    109
  24. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, we're going to support the full .NET 8 BCL, which include HTTP/2 support. I don't yet have an ETA for this to be publicly available, but when it is, HTTP/2 support will be there.
     
    rdjadu, Eclextic, bdovaz and 2 others like this.
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    No, I don't have an update. Honestly we've not started to look at this yet. We do plan to in the future though.
     
  26. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,130
    Awesome. One more question. Until today asset store still not yet adopt package manager. Is that official want to wait until shipping coreclr together with package manager migrated to Microsoft Nuget package then only asset store will adopt package manager?
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm not sure about plans for the Asset Store to work with either the Unity Package Manager or NuGet, sorry! We expect that the .NET Modernization work will allow NuGet to work with Unity, but I suspect we will need to wait until it is released to see how (or if) the Asset Store will adopt it.
     
  28. stevphie123

    stevphie123

    Joined:
    Mar 24, 2021
    Posts:
    89
    NAOT works on consoles just fine, as long as the CPU used in those consoles already supported by RyuJIT
     
    CaseyHofland and Thaina like this.
  29. Petko147

    Petko147

    Joined:
    Oct 18, 2021
    Posts:
    11
    I would be soooo happy if you decide to use NuGet for Asset Store. It would allow for a fantastic unified user experience across packaging in .NET.
    Developers building apps or websites on top of .NET uses NuGet and are very used to it.
    It could be, that Asset Store don't run on top of NuGet, but it would be also possible to install NuGet more easily then now, it could be fine. But in my opinion, to have unified user experience for packaging in Unity that matches the rest of .NET ecosystem would just be even better :) It would be super awesome indeed !

    And if NuGet has some limitations, so it is not very well suited for Unity, I am absolutely sure Microsoft will be willing to cooperate on it with you. As far as I know, you already cooperate with Microsoft, and they surely appreciate their close connections with you, so they might simply improve NuGet or what, if you need it.
     
    DHAR1 and bdovaz like this.
  30. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    617
    This would already work as all an asset developer would need to do would be to add a .csproj with the corresponding nugets to their package
     
    Anthiese likes this.
  31. DHAR1

    DHAR1

    Joined:
    Dec 14, 2022
    Posts:
    3
    Your vision is quite correct—it involves creating a system that not only streamlines the swift and easy sharing of content, much like an asset store, but also goes further by integrating versioning capabilities and ensuring seamless compatibility. Through specifying the TargetFramework, the ability to pinpoint which Unity version is compatible becomes feasible. Furthermore, this vision extends to Unity itself becoming available as a NuGet package, granting developers the simplicity of specifying, for instance, "use version X with package X" or opting for version-agnostic compatibility using the standard framework, and so forth.

    To play devil's advocate, it's plausible that Unity generates substantial revenue from its asset store, and adopting this vision might allow developers to implement their own licensing and usage requirements for their products. In-house development might significantly contribute to Unity's revenue. However, if Unity were to enable NuGet packages to load assets and more, it would undoubtedly enhance the developer experience immensely.
     
    Petko147, bdovaz and Nad_B like this.
  32. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    They already can and do this, see Jbooths own store or the Synty store. Its completely allowed, and Unity doesnt appear to see this as a threat.
     
  33. Eclextic

    Eclextic

    Joined:
    Sep 28, 2020
    Posts:
    142
    If the mods take this down, then I guess you guys only did your job... (This is unrelated anyways...)

    Happy new year!
    (Living in Germany, time is currently 23:59 lol)
     
  34. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    617
    This thread is 46 pages long and honestly, it’s been a nice place to hang out. A happy new year everyone, make sure to do more than just coding ;)
     
    bdovaz, Eclextic and Lurking-Ninja like this.
  35. EP-Toushirou

    EP-Toushirou

    Joined:
    Nov 19, 2019
    Posts:
    40
  36. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,184
    I think it's impossible, too much breaking change
     
  37. Tuncle

    Tuncle

    Joined:
    Oct 1, 2018
    Posts:
    23
    Eclextic and CaseyHofland like this.
  38. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    JiRo_Dev likes this.
  39. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    248
    There was a thread about a general overhaul a few months back. official even i think. What's happened to it?
     
  40. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,130
    Hi @JoshPeterson. Currently I found that the current mono at player runtime at latest Unity 2022.3.16f1 LTS at the time of writing really not gc spike friendly like 10kb+ every frame that it will keep increasing mono memory and even call GC.Collect method won't able to reduce the mono memory size back the original size that just launch the player runtime. But looks like at pure .NET player runtime won't increase memory size even it has huge gc spike every frame. So I would like to ask will Unity player runtime finally become gc spike friendly that won't keep increasing player runtime memory size after upgraded from Mono to CoreCLR?
     
  41. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    617
    You can enable incremental garbage collection to reduce spikes.
    https://docs.unity3d.com/Manual/performance-incremental-garbage-collection.html

    If the memory size cannot be reduced back to its original size you will need to profile if there's data leaking somewhere. Maybe the memory profiler can help (though I've never used it and this is not the right thread to ask questions about it).
    https://docs.unity3d.com/Packages/com.unity.memoryprofiler@1.0/manual/index.html

    CoreCLR will help with garbage collection but you should never rely on new features to save your game for you. Profile, optimize, reduce. It's good practice no matter how much CoreCLR would help.
     
  42. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,130
    I enabled incremental garbage collection but the mono memory size still keep increasing.

    Unfortunately the project I'm working on require to integrate API that is not gc free which I have no control of and can't do anything with it.
     
  43. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This is probably worth taking to a new thread for discussion. I suspect it is something we can investigate, but let's not get too much more into the details on this thread.
     
  44. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Was that part of this thread or another one? I don't recall, although I also have a vague recollection that this was discussed.
     
  45. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    617
    I remember words being thrown around about removing the deprecated
    MonoBehaviour.rigidbody
    and friends.
     
    Eclextic and Thaina like this.
  46. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,184
    Some of deprecated removing is possible. But changing Vector3.x into Vector3.X hardly be possible. Everything will break
     
  47. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, thank you! This is definitely on the table - we do expect to remove deprecated things.

    And yes, we do not expect to make changes like this!

    Thanks to both of you - these are good examples that hopefully highlight our plans.
     
    Eclextic and CaseyHofland like this.
  48. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    612
    Speaking of this... There was a talk at a Unite few years ago about something called "MonoBehaviour 2" like redesigning it from scratch. Also, I remember one of the core Unity developers saying "We didn't know what we were doing when we first designed it".

    Later, I didn't hear anything about this for many years. @JoshPeterson do you have any information you can share about this?
     
  49. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I don't have much sorry! I know there have been a few internal efforts to redesign this. I've not been directly involved with them. It would not surprise me if we do try something in the future, but that is about all I know.
     
    Xtro likes this.
  50. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,184
    Isn't that ECS ?