Best way to iterate over shared component chunks in a job?

Hey, quick question. I have a bunch of entities grouped up by a shared component’s unique value. I would like to pass all the entities grouped up by each shared component value to a job, so as to build a native container from them. In other words, the ideal input parameters for the job’s execution would be something like:

  • MySharedComp _sharedComp
  • Entitiy[ ] _entitiesArray
  • MyCompA[ ] _compAArray

The only problem is that I don’t know how many unique shared component values there are, and this may change over time. So doing a fixed entity query with a SetFilter(Value = something) is not possible. It’s a double iteration in the form of:

foreach unique shared component value
foreach entity within the group

What would be the cleanest way to do this do you think? Thanks!

Use EntityManager.GetAllUniqueSharedComponentData API to get all unique shared component data then set the filter to your EntityQuery using that data, finally extract the data from the filtered query using ToEntityArray/ToComponentDataArray API.

Thanks!