What is the best way to iterate over entities of a query over time

For now - yes a bit, as they’ll be converted to IJobChunk by ILPP, but in the next releases, when codegen will be changed to IJobEntityBatch, they’ll be the same and ForEach version will be even a bit faster in some cases as Unity codegen will optimize them under the hood as much as possible.

2 Likes

I’m writing an UtilityAI myself and wondered about the same issue but performance is good enough at the moment to do everything every frame so i haven’t bothered implementing it yet.
Couldn’t you use SharedComponents and just have a static int parameter in them that splits up your Entities in chunks you can filter? So every Frame your System would just increase the parameter by one and processes all chunks where the shared component has that value. if you reach the highest value you start from the beginning without ever changing the contents of the shared component and thus never changing the chunk layout. This way even if Entities change their chunk based on other systems you still guarantee you process every entity exactly the same amount of times.

The goal was to minimize entity copies thus using the chunk component/versioning values to find it out, otherwise yes a shared component could be used but it would mean all components in a chunk need to be coopied after processing unless unity was smart enough that if all entities in a chunk changed their shared component value into the same value, it wouldn’t copy them and just change the index that they maintain for chunks and shared components if any.

Changing the shared component index would only happen if you needed to rebalance the number of entity per shared index value.

1 Like

I did not mean that unity prefetches data but depending on the data layout and implementation of ComponentDataFromEntity, it might cause a a cache miss even if the entities which you give to it subsequently reside in the same array beside each other. I’ll check its impelemntation on saturday and report back.

Cannot wait for GDC because hopefully unity releases animation package in preview (no longer experimental) and the shooter demo with it which means we can add the last part of the puzzle to our game and I’m super excited to show it to you guys here. We are building the website, doing some models and … to look for publishers and using DOTS despite the hardships of early technology was a great decision.

1 Like