Unity Technologies release of Unity 2021.2 came out in late October and it is filled with some amazing features and improvements for both artists and programmers.  For artists it includes improvements to both the HD and universal render pipelines like  decals, realtime lighting, and volumetric clouds and new features for the visual effects and shader graphs.  It also comes with a new addition to the UI Toolkit in the form of runtime UI authoring.

You can now use Unity’s powerful new UI creator to build interfaces for your game  along with custom editor extensions. And to that end Unity has really delivered some nice improvements.  We got incremental builds, custom build settings, and feature sets in the package manager. But there’s one upgrade in 2021.2 that’s particularly important to us developers, and that’s exactly what we’re going to talk about in this article

To understand why the upgrade in Unity 2021.2 we’re going to cover is so important, it’s  useful to review how scripting works in Unity under the covers. One of Unity’s main selling points is that it has industry-leading multiplatform support. You can write your game code once and deploy it across more than 20 different platforms. This is possible thanks to .NET is a free, open-source development platform. And because it’s open-source, it has quite a few implementations that are currently being  maintained.

One of those implementations is the open-source project called Mono. Mono was created by a company called Ximian and it’s created back in 2003, it’s  main goal has been to support a wide range of architectures and operation systems. That’s why it was the perfect candidate to support Unity scripting layer. However, due to some licensing issues that go well beyond the scope of this video, Unity Technologies decided to fork the open-source project and maintain its own implementation of Mono that it bundles with the editor. And that is the framework that powers scripting in Unity.Today a customized version of .NET that Unity is responsible for maintaining and keeping up to date with the latest version of the .NET API. As you can imagine, maintaining both a game engine and an implementation of .NET can be  a little challenging. And if you’ve done enough programming in Unity, you’ve probably come across at least one class or C# feature that just wasn’t supported by the editor.

The reason is because for the longest time Unity’s implementation of Mono wasn’t  kept fully up to date, Until now. As Unity 2021.2, the Unity-bundled mono version has been upgraded from 2018 to a more recent version that allows improved support for C# version 8, enables parallel debugging, and enhances implementation quality. And this new version also supports the .NET Standard 2.1 API.  Sounds exciting, right?

But what exactly does it mean from a practical standpoint? Let’s start with the .NET Standard 2.1 API. I mentioned earlier that there are many implementations of .NET that are currently being maintained. Each one of these implementations was created obsentislby to solve some sort of problem or to be particularly good at creating a specific type of application. For example, the .NET Framework is an implementation that was created specifically for developing  web applications. And, of course, Unity’s implementation is really good for making games. However while every implementation is different, they all have to abide by a standard API. In other words, whether I’m using Mono or the .NET Framework or .NET Core I expect to  have access to a set of base System classes that I can use to develop my application. This standard API is known as the .NET Standard and, as confusing as it may be, it’s versioned  separately from the implementations that fulfill it.

In the case of Unity, we’ve been stuck with a legacy version of the .NET Standard.  But with the release of Unity 2021.2 you can now set your project’s API compatibility level to .NET Standard 2.1 and get access to the entire API that comes with it. One particularly useful feature is the range syntax which is made possible through the Range class. Range is used by the compiler to support a special syntax for arrays that you can use  to reference a subset of an array.

If you’d like to know what other features are available in .NET Standard 2.1, you can  check out the .NET API browser over at Microsoft’s website. Now there’s a lot of information to unpack there, and you’ll even notice that there are other .NET API’s that I didn’t mention, but the important thing to know is that Unity now supports a modern API. You’ll be able to use all of it’s features and leverage modern third-party plugins that rely on this standard.

The other exciting thing about Unity 2021.2 is it’s improved support for C# version 8. Unity has supported a subset of C# 8 since 2020 but this latest release gives us full access to all of the features that version 8 has to offer. That means we’ll finally be able to use default interface methods, which is something I’ve seen a lot of developers ask for.  This feature let’s you add concrete implementations to your interfaces and comes in handy when you need to add new methods to an interface without breaking existing implementations. And that’s not all.

In addition to default interface methods, there’s switch expressions, using declarations,  static local functions, and a ton more syntactic sugar that makes C# that much more enjoyable  to work with. To explore more, you can find all C# 8’s features on Microsoft’s website. I’m really excited to see that Unity is working on modernizing their scripting layer.  In recent years, a lot of emphasis has been placed on shiny new features that allows Unity  to target new markets, like real time animation and the film industry. And I fully support that but I just don’t want to see it come at the cost of continued support for developers, which it looks like it isn’t. Let me know what you think about the changes in the comments below.  Are there any new features that you’re particularly excited about? Or are there any that you wish you could have seen?

If you enjoyed this article, be sure to leave a comment. And sign up for the Newsletter for more content like this.  Thanks for reading and, as always, I’ll catch you in the next article.

By Technology Researcher

Analyst studies emerging trends in the information technology.

Leave a Reply