is it me or is there no way to add a ComponentData or chunkComponentData directly to an ArchetypeChunk at this phase?
I’m really surprised that i can’t find anyone anywhere looking for this API!
How can you tag / add components to chunks based on their ComponentData values?
the only way to change an ArchetypeChunk is through EntityQueries and that is extremely limited! (no way to control ComponentData values)
eg:
[BurstCompile]
private struct DisableChunksInRange : IJobChunk
{
[ReadOnly] public int2 CurrentRegion;
[ReadOnly] public ArchetypeChunkComponentType<WorldMapRegionChunk> WorldMapRegionChunkType;
public EntityCommandBuffer.Concurrent CommandBuffer;
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
{
var wmrValue = chunk.GetChunkComponentData(WorldMapRegionChunkType).value;
if (math.abs(CurrentRegion.x - wmrValue.x) >= 1 && (math.abs(CurrentRegion.y - wmrValue.y) >= 1) )
{
//Chunk need to be disabled or modified
}
}
}
I don’t think chunk component are really used that much tbh.
The only place Unity uses chunk components I’m aware of is is hybrid renderer for chunk info
Yes, but it still Component structure Oriented and not data oriented.
let’s say we have a TOP-DOWN game with a large map containing thousands of chunks with
entities having physics And/or rendering components, these chunks are divided by regions, how can we prevent physics and Frutum Culling calculations in vain for entities which are too far ?
the way i see it, is just to disable chunks with out of range regions value .
but how to do it by chunk and not by entity if there is no Api to operate on chunks instead of entities?
Without going too much into detail, our game is very similar to what you’re talking about.
In most top down games I don’t think you’d really need to do frustum culling as you’re camera angle kind of limits how far you will see objects, instead we just break everything up into regions based on a grid around player.
Originally this was mostly done for networking more than culling, as on PC we actually don’t cull anything; we simulate the entire world at all times though recently we started culling entities on consoles that are far away.
our approach does this mostly on a per entity basis (though we do use a chunk component for network serialization of this data)
Codegen jobs that work with arbitrary NativeArray since there’s no intuitive way to combine EntityQueries (only descriptions) would solve this problem.
We’ve needed a dedicated thread for little missing EntityManager and EntityCommandBuffer APIs for a while now.