I am making chunk based game and logic that spawns those chunks is quite slow. I would like to utilize jobs along with CommandBuffer to make it faster, but how can I pass list of Components to job so that I can use CommandBuffer to add them to the Entity?
I don’t think it makes tremendous sense to pass IComponentData or ISharedComponentData to instantiation jobs while:
A). Jobs already can access existing IComponentData already via ForEach… jobs (but specific details depends on entities package version)
B). You don’t need CommandBuffer to instantiate entities but EntityManager
var components = new ComponentType[]{
, ComponentType.ReadWrite<LocalToWorld>()
, ComponentType.ReadWrite<RenderBounds>()
, ComponentType.ReadWrite<WorldRenderBounds>()
, ComponentType.ReadWrite<ChunkWorldRenderBounds>()
, ComponentType.ReadOnly<RenderMesh>()
};
var archetype = entityManager.CreateArchetype( components );
var instance = entityManager.CreateEntity( archetype );
entityManager.SetComponentData( instance , localToWorldData );// transform matrix
entityManager.SetComponentData( instance , new RenderMesh{ mesh = my_mesh , material = my_material );
entityManager.SetComponentData( instance , otherComponentData );
C). NativeArray is a better way of doing just that
NativeArray<myType> inputData;//fill it
var job = new MyJob{ input = inputData };
job.Schedule();