System.Lazy?

when implementing the lazy script that @sampattuzzi gave us, an already built in Lazy came up… do these do the same thing?

Screen Shot 2020-05-16 at 8.24.55 AM

1 Like

They do similar things, although System.Lazy includes a lot of extra code for handling true Async operations that we don’t even need. (Despite the term “coroutine” our Coroutines are not the same thing as a truly Async operation, like a Task, which can’t see any of the Unity API).
Also, I’m not sure the System.Lazy even works in all versions of Unity… It’s introduced in Net 4.8 and to my knowledge, all versions of Unity before 2017 are stuck on 3.5, and later ones can use up to 4.6. Another note: If you build to native format, not all platforms support 4.x features, Android being a great example.

Here’s a link to the Source of System.Lazy
https://referencesource.microsoft.com/#mscorlib/system/Lazy.cs

3 Likes

Have to say, I found using Sam’s lazy system way more easy to implement too, can’t remember why exactly, haven’t used lazies in a while so… yeah, I’ll have to check that later.

Personally, I found the best implementation to be in Kotlin, where you just declared the implmentation right there when you allocated the variable. Seamless.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms