Burst is Unity’s high-performance compiler for DOTS code. It uses SIMD instructions to apply the same operation to multiple data values at once, accelerating array-based gameplay work. section 12.0 section 12.6
Using Burst comes with practical constraints:
- Code must use NativeArray and DOTS-compatible types, such as float2; this ties the code to Unity and limits reuse for server-side gameplay validation. section 12.5 section 12.6
- Burst can process four floating-point values in one 128-bit register. Its performance benefits come with added code complexity. section 12.5
Listing 12.3 Allocating NativeArray gameplay data
public static void AllocateGameData(GameData gameData, Balance balance)
{
gameData.EnemyPosition =
new NativeArray<float2>(balance.MaxEnemies, Allocator.Persistent); #A
gameData.EnemyType =
new NativeArray<int>(balance.MaxEnemies, Allocator.Persistent);
gameData.AliveEnemyIndices =
new NativeArray<int>(balance.MaxEnemies, Allocator.Persistent);
gameData.DeadEnemyIndices =
new NativeArray<int>(balance.MaxEnemies, Allocator.Persistent);
gameData.EnemyVelocityNative =
new NativeArray<float>(balance.EnemyVelocity, Allocator.Persistent);
}Example NativeArray allocation for gameplay data used by Burst-oriented code. section 12.1.2
