Version: Unity 6.6 (6000.6)
Language : English
High Performance C# introduction
String support

Static read-only fields and static constructor support

Burst evaluates all static fields and all static constructors at compile time. It evaluates all the static fields and the static constructors for a given struct together.

Burst only supports read-only static fields. A static field that isn’t read-only in a Burst-compiled struct causes a compilation error.

When Burst fails to evaluate any static field or static constructor, all fields and constructors fail for that struct.

When compile-time evaluation fails, Burst falls back to compiling all static initialization code into an initialization function that it calls once at runtime. This means that your code needs to be Burst compatible, or it will fail compilation if it fails compile-time evaluation.

An exception to this is that there’s limited support for initializing static read-only array fields as long as they’re initialized from either an array constructor or from static data: - static readonly int[] MyArray0 = { 1, 2, 3, .. }; - static readonly int[] MyArray1 = new int[10];

Language support

Burst doesn’t support calling external functions and function pointers.

It supports using the following base language with static read-only fields and constructors:

  • Managed arrays
  • Strings
  • Limited intrinsic support:
    • Unity.Burst.BurstCompiler.IsEnabled
    • Unity.Burst.BurstRuntime.GetHashCode32
    • Unity.Burst.BurstRuntime.GetHashCode64
    • Vector type construction
  • Limited intrinsic assertion support:
    • UnityEngine.Debug.Assert
    • NUnit.Framework.Assert.AreEqual
    • NUnit.Framework.Assert.AreNotEqual
  • Simple throw patterns. Any exceptions thrown during evaluation become compiler errors.

Additional resources

High Performance C# introduction
String support
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961