- Home /
THe question was based on faulty information
ECS: How to access to separate "groups" of same-archetype entities?
This is a program where you launch groups of objects into the play space, and apply forces to groups of entities. I need to apply different forces to different groups of entities. How can I get access to separate "groups" of same-archetype entities?
Current approach: "GroupIdComponent in an IJobForEach": I add a groupIdComponent to each entity on creation with an int field that represents their group, then in the execution of an IJobForEach(), I apply force based on the groupId. The information for how much force to apply to each groupId is retrieved from a dictionary stored elsewhere. At 10,000 entities this is a 20ms operation each frame and this is too slow.
Proposed Solution:"JobComponentSystem" What I can think of is to use a job component system, get access to these same-archetype entity groups, and call the job on each of them and pass in the force value specific to that group. However, I do not know how to get access to these groups. The only way I could do it currently is to pass into the struct a dictionary with the force to be added to every group, and that entity gets the force from its group from the dictionary. That is passing in a dictionary with values for every group when really it just needs the value for its own group.
Advice/feedback would be greatly appreciated.
Hey there,
i faced a similar problem ina project once. there i introduced different tagcomponents. but since this is rather rigid and i only had 2 groups this probably wont work for you.
Are you using burst? And can you share some code?
Hey thanks for the reply, i got it figured out. Had to just learn a little more about ecs. Have a great day! For some reason I thought that you couldn't reference static variables of other classes inside a job and you can. The other part of the solution was to create "entititycaptians" that are entities in charge of updating a bunch of static info for other entities.
Hey,
thanks for co$$anonymous$$g back on this. would you $$anonymous$$d sharing your experience a bit more detailed as an answer? As you probably have realised yourself while researching this topic there is only little up to date information on this topic.
Also note that in case you want to use the burst compiler (which i can highly recommend :D) you cannot access static references anymore so i wouldn't rely on this too much.