As the title said, what’s the best way to iterate though entities with SharedComponentData.
What I currently found out is to use custom archetype chunk iteration, which works, but it’s way to much of boilerplates to write(create querytype, archetypecomponenttype for getting native arrays of components) and then use the most common IJob for the processing.
Is there any other way to do the job like IJobProcessComponentData? so that I can simply get the components/sharedcomponents directly and then process them?
Entities.ForEach works if you put SCD in the first argument of the lambda. IJobForEach (IJPCD) also works if you Schedule with an EntityQuery (ComponentGroup) with the SCD type.
Are you saying SCD can be accessed in a job? I was under the impression this was not possible.
SCD type and each chunk’s SCD index could be, but not SCD value.
My “works” means the entities are of that that has the SCD type attached, because OP was not saying about accessing the actual value. But just iterate through entities with the SCD.
hmmm, actually I wanted to access the value of SCD inside a job.
So basically what is possible now is to prefetch the value first and then pass them to a job, am I correct?
Yes, you could also read here https://gametorrahod.com/everything-about-isharedcomponentdata/ why it seems like a trouble. The “sharing” mechanism works just like C++ pointer but with a simple integer. ECS wouldn’t allow you to “follow the pointer” from a job.
We had a discussion about getting SCD value in a job (not possible directly as pointed out before) - pass to job in a container (i.e. hashmap), copy to CCD (chunk component data) which is accessible in a job, depending on the use case also assess if SCD has advantage over ICD
[How to read SharedComponentData in IJobChunk?]( How to read SharedComponentData in IJobChunk? page-2#post-4314520)
Sorry for the late reply, and thanks alot for the blog post, which helped me alot with understanding what really is going on.
Btw. I love your blog, really nice articles in there.
Ps. It’s recommended to use 3rd party audio middlewares instead of the built in audio system of unity, if you have more requirements in Audio. We used Criware, and the no latency playback is very good and even with compression. Criware’s price is also acceptable for indie developers