Burst works on a subset of .NET that doesn’t let you use any managed objects or reference types in your code (classes in C#).
The following sections give more details about the constructs that Burst supports, and any limitations they have.
Burst supports the following built-in types:
boolbyte/sbyte
doublefloatint/uint
long/ulong
short/ushort
Burst doesn’t support the following built-in types:
chardecimalstring because this is a managed type
Burst supports read-only managed arrays loaded from static read-only fields:
[BurstCompile]
public struct MyJob : IJob {
private static readonly int[] _preComputeTable = new int[] { 1, 2, 3, 4 };
public int Index { get; set; }
public void Execute()
{
int x = _preComputeTable[0];
int z = _preComputeTable[Index];
}
}
However, accessing a static read-only managed array has the following restrictions:
If you’ve used an unsupported static constructor, Burst produces the error BC1361.
For more information on how Burst initializes arrays, see Static readonly fields and static constructors.
Burst doesn’t support managed arrays. Instead, use a native container such as NativeArray<T>.
Burst supports the following structs:
Note: Structs with an explicit layout might generate non-optimal native code.
Burst supports the following struct layouts:
LayoutKind.SequentialLayoutKind.ExplicitStructLayoutAttribute.PackStructLayoutAttribute.SizeBurst supports System.IntPtr and System.UIntPtr natively as intrinsic structs that directly represent pointers.
Burst supports generic types used with structs. It supports full instantiation of generic calls for generic types that have interface constraints, for example when a struct with a generic parameter needs to implement an interface.
Note: There are restrictions if you use generic jobs.
Burst can translate vector types from Unity.Mathematics to native SIMD vector types with the following first class support for optimizations:
bool2/bool3/bool4
uint2/uint3/uint4
int2/int3/int4
float2/float3/float4
Tip: For performance reasons, use the 4 wide types (bool4, uint4, float4, int4) over the other types.
Burst supports all enums including enums that have a specific storage type, for example, public enum MyEnum : short.
Burst doesn’t support Enum methods, for example Enum.HasFlag.
Burst supports any pointer types to any Burst supported types
Burst supports Span<T> and ReadOnlySpan<T> types in the Unity Editors that support them.
You can only use span types in Burst jobs or function-pointers, but not across the interface to them. This is because in C#’s implementation of the span types it supports taking spans into managed data types (like a managed array). For example, the following code is invalid:
[BurstCompile]
public static void SomeFunctionPointer(Span<int> span) {}
This is because Span is used across the managed and Burst boundary. In Burst, span types respect any safety check setting, and only perform performance-intensive checks when safety checks are enabled.
Burst supports value tuples ValueTuple<T1,T2> in Burst-compiled jobs or static methods, but not across the interface to them. This is because value tuples are of struct layout LayoutKind.Auto. Burst does not support LayoutKind.Auto (to see a list of struct layouts Burst supports see the section Struct types).
However, one can use a regular struct to emulate a tuple like so:
[BurstCompile]
private struct MyTuple
{
public int item1;
public float item2;
}