Hi all,
I’m learning DOTS stack by porting the Unity training sample HighwayRacers to DOTS.
I use Unity 2023.3.13f1, Entities 1.0.16 and Burst 1.8.12.
I wrote a simple system, that spawn entities (cars):
[UpdateInGroup(typeof(InitializationSystemGroup), OrderLast = true)]
public partial struct SpawnCarsSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
GameConfig gameConfig = SystemAPI.GetSingleton<GameConfig>();
Entity carPrefab = gameConfig.CarPrefab;
Random rand = new Random(42);
EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp);
for (int i = 0; i < gameConfig.CarCount; i++) {
Entity car = ecb.Instantiate(carPrefab);
float defaultSpeed = rand.NextFloat(gameConfig.DefaultSpeedMin, gameConfig.DefaultSpeedMax);
ecb.SetComponent(car, new CarData {
Distance = rand.NextFloat() * gameConfig.HighwaySize * 4,
LaneIndex = rand.NextInt(0, gameConfig.HighwayLanes),
DefaultSpeed = defaultSpeed,
OvertakePercent = rand.NextFloat(gameConfig.OvertakePercentMin, gameConfig.OvertakePercentMax),
LeftMergeDistance = rand.NextFloat(gameConfig.LeftMergeDistanceMin, gameConfig.LeftMergeDistanceMax),
MergeSpace = rand.NextFloat(gameConfig.MergeSpaceMin, gameConfig.MergeSpaceMax),
OvertakeEagerness = rand.NextFloat(gameConfig.OvertakeEagernessMin, gameConfig.OvertakeEagernessMax),
VelocityPosition = defaultSpeed,
VelocityLane = 0.0f
});
}
ecb.Playback(state.EntityManager);
state.Enabled = false;
}
}
Everything works fine in the editor, but when I build & run the game, the unity player crashes:
Burst seems to not like the SystemAPI.GetSingleton<GameConfig>();
in builds…
If I remove the BurstCompile attribute, it doesn’t crash.
What am I doing wrong? Should I report this to Unity as a bug?
PS: I think it’s not necessary performance-wise to BurstCompile this job, but I don’t understand why it crashes only in the player and doesn’t give any warning in the editor.