Enables support for C# 9's record
types and
init
setters in Unity.
Unity 2021.2 technically supports C# 9, but some of its language features rely on runtime libraries that aren't available in .NET Standard 2.1. This package defines an internal class that these features require in order to function.
The included assembly originally came from this NuGet package (source).
Follow the instructions given here to install this package in your project via OpenUPM.
This package is delivered as a precompiled assembly
so that all assembly definitions reference it automatically.
There's no public API unless you count the enabled language features.
As a result,
you can get started
using standard record
s and
init
setters immediately.
There are some minor caveats when using this package:
- If an assembly definition uses the "Override References" setting to reference precompiled assemblies explicitly,
you'll need to add a reference to
IsExternalInit.System.Runtime.CompilerServices
. Otherwise, thatasmdef
won't be able to userecord
s orinit
. - Unity doesn't currently support serializing or editing
record
s, so you'll need to implement that yourself. - A future release of Unity with built-in support for
record
s andinit
may break this package due to potential naming conflicts with theSystem.Runtime.CompilerServices
namespace. When that happens, I'll add a#define
constraint tied to it to minimize disruptions.
This package should work in any version of Unity that provides at least partial support for C# 9, starting with 2021.2.
The provided assembly is disabled in older versions of Unity (i.e. versions that don't define UNITY_2021_2_OR_NEWER
).