Does this look right to you @soft mulch ?
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var physicsWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>().CollisionWorld;
var bulletQuery = SystemAPI.QueryBuilder()
.WithAll<LocalTransform, Bullet>()
.Build();
var bulletTransforms = bulletQuery.ToComponentDataArray<LocalTransform>(Allocator.TempJob);
var bullets = bulletQuery.ToComponentDataArray<Bullet>(Allocator.Temp);
var bulletEntities = bulletQuery.ToEntityArray(Allocator.Temp);
NativeArray<RaycastInput> raycastInputs = new(bulletTransforms.Length, Allocator.TempJob);
NativeArray<RaycastHit> raycastResults = new(bulletTransforms.Length, Allocator.TempJob);
for (int index = 0; index < bulletTransforms.Length; index++)
{
float3 start = bulletTransforms[index].Position;
float3 end = start * 1.25f;
raycastInputs[index] = new RaycastInput()
{
Start = start,
End = end,
Filter = new CollisionFilter()
{
BelongsTo = ~0u,
CollidesWith = ~0u,
GroupIndex = 0
}
};
}
var batchRaycastResult = ScheduleBatchRayCast(physicsWorld, raycastInputs, raycastResults);
batchRaycastResult.Complete();
for (int index = 0; index < raycastResults.Length; index++)
{
if (raycastResults[index].Entity == Entity.Null)
{
state.EntityManager.AddComponent<Damage>(raycastResults[index].Entity);
state.EntityManager.SetComponentData<Damage>(raycastResults[index].Entity, new()
{
Value = bullets[index].Damage
});
state.EntityManager.AddComponent<Destroy>(bulletEntities[index]);
}
}
}