Remix.run Logo
pjc50 5 hours 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.

tyleo 4 hours ago | parent | next [-]

Unity is currently on C# 9 and that IEnumerable trick is no longer needed in new codebases. async is properly supported.

Deukhoofd 3 hours ago | parent | prev | next [-]

Thankfully 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-st...

pjmlp 2 hours ago | parent | next [-]

For several years now, I wonder if it will ever happen.

Deukhoofd an hour ago | parent [-]

Well, this is at least an update from earlier this month with a clear roadmap of how they're going to get there. There's hope!

Rohansi 3 hours ago | parent | prev [-]

One 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 2 hours ago | parent [-]

Why wouldn't they use the GC that comes with the dotnet AOT runtime?

pjmlp 2 hours ago | parent [-]

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

Philip-J-Fry 4 hours ago | parent | prev | next [-]

>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 5 minutes ago | parent [-]

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

debugnik 5 hours ago | parent | prev | next [-]

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

Rohansi 3 hours ago | parent | next [-]

It'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 18 minutes ago | parent [-]

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

nananana9 4 hours ago | parent | prev [-]

Unity 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/ScriptReferenc...

debugnik 4 hours ago | parent [-]

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

ahoka 4 hours ago | parent | prev | next [-]

IIRC generators and co-routines are equivalent in a sense that you can implement one with the other.

Sharlin 2 hours ago | parent [-]

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

repelsteeltje 5 hours ago | parent | prev [-]

Not too different from C++'s iterator interface for generators, I guess.