3 ms·
Always jarring to see how Unity is stuck on an ancient version of C#. The use of IEnumerable as a "generator" mechanic is quite a good hack though.
by pjc50 8mo ago
Always jarring to see how Unity is stuck on an ancient version of C#. The use of IEnumerable as a "generator" mechanic is quite a good hack though.
- repelsteeltje 8mo agoNot too different from C++'s iterator interface for generators, I guess.
- debugnik 8mo agoNot that ancient, they just haven't bothered to update their coroutine mechanism to async/await. The Stride engine does it with their own scheduler, for example. Edit: Nevermind, they eventually bothered.
- nananana9 8mo agoUnity has async too [1]. It's just that in a rare display of sanity they chose to not deprecate the IEnumerator stuff. [1] https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Awaitable.html https://docs.unity3d.com/6000.3/Documentation/ScriptReferenc...
- debugnik 8mo agoOh I totally missed this, thanks! I was overly confident they wouldn't have bothered, given how long it was taking. The last time I used Unity was 2022.3, which was apparently the last version without Awaitable.
- Rohansi 8mo agoIt's ancient. The latest version of Unity only partially supports C# 9. We're up to C# 14 now. But that's just the language version. The Mono runtime is only equivalent to .NET Framework 4.8 so all of the standard library improvements since .NET (Core) are missing. Not directly related to age but it's performance is also significantly worse than .NET. And Unity's garbage collector is worse than the default one in Mono.
- debugnik 8mo agoThe runtime is absolutely ancient, but I think the version number says more about C#'s churn than about how outdated the language version is. Take my opinion on C# with a grain of salt, though, I was an F#-er until the increasing interop pains forced me to drop it.
- Rohansi 8mo agoThere were also a lot of performance improvements to .NET over the last few years.
- tyleo 8mo agoUnity is currently on C# 9 and that IEnumerable trick is no longer needed in new codebases. async is properly supported.
- ahoka 8mo agoIIRC generators and co-routines are equivalent in a sense that you can implement one with the other.
- Sharlin 8mo agoGenerators are a subset of coroutines that only yield data in one direction. Full coroutines can also receive more input from the caller at every yield point.
- Philip-J-Fry 8mo ago>The use of IEnumerable as a "generator" mechanic is quite a good hack though. Is that a hack? Is that not just exactly what IEnumerable and IEnumerator were built to do?
- jayd16 8mo agoIt feels hacky because you have to (had to?) use it as the async/await tool and because of that the types you're generating and how they are handled is a huge mess. Really you're generating the vague concept of a yield instruction but you can return other coroutines that are implicitly run and nest your execution... Because of this you can't wait less than a frame so things are often needlessly complicated and slow. It's like using a key to jam a door shut. Sure a key is for keeping doors closed but...
- Deukhoofd 8mo agoThankfully they are actively working towards upgrading, Unity 6.8 (they're currently on 6.4) is supposed to move fully towards CoreCLR, and removing Mono. We'll then finally be able to move to C# 14 (from C# 9, which came out in 2020), as well as use newer .NET functionality. https://discussions.unity.com/t/coreclr-scripting-and-ecs-status-update-march-2026/1711852 https://discussions.unity.com/t/coreclr-scripting-and-ecs-st...
- Rohansi 8mo agoOne annoying piece of Unity's CoreCLR plan is there is no plan to upgrade IL2CPP (Unity's AOT compiler) to use a better garbage collector. It will continue to use Boehm GC, which is so much worse for games.
- pjc50 8mo agoWhy wouldn't they use the GC that comes with the dotnet AOT runtime?
- pjmlp 8mo agoProbably because the AOT runtime doesn't run on game consoles, straight out of the box. Capcom has their own fork of .NET for the Playstation, for example. I don't know what kind of GC they implemented.
- Rohansi 8mo agoThey just haven't announced any plans to do so yet. They might one day. They will not be using .NET AOT probably ever though. Unity's AOT basically supports full C# (reflection etc) while .NET opted to restrict it and lean more on generated code.
- pjmlp 8mo agoFor several years now, I wonder if it will ever happen.
- 8mo ago