One set of Entities affecting an other set of Entities - Best Practice

Hi folks,
I have a best practice question. I am fairly new to the DOTS world, but I got the principles and have my first things running. However, I am struggling with the concept of having different Entities with different Components affecting each other.

Usually I write a System Based Class that does work for a couple of entities with one or more components. I get that principle and I can work with this.

But I came to the point, where I have one kind of entity which affects an other kind of entity. I don’t quite see how I can handle this, or rather whats the supposed way of doing this is.

The only thing I can come up with, doing an entity query with the first set of entities, storing the needed information (somehow) and then doing a second query with the other type of entity and modifying them with the previously stored data. And doing all that in the update method of the same system class.

This doesn’t feel right and I think there is a better, more sophisticated way of doing this.

I hope I could make myself clear, any help or examples are greatly appreciated.

Cheers
Santo.

Sounds feasible to me. I think I have done the same (can’t seem to find an example to show you). Just create an EntityQuery in your SystemBase OnCreate(), then execute the query during the OnUpdate().

//pseudo code...

OnUpdate() {
  var others = _query.ToNativeArray();

  Entities
  .ForEach( (Enity entity) = > {
 
  foreach (var thing in others) {
   ...
  }
 })
.Schedule();

You would use component data from entity and use a random access. Not everything in ecs has to be linear. Having one set of entities affect another is a random access problem, so don’t worry about using component data from entity.

And yea you would use two entity queries.

Can you give an example of the problem you are trying to solve? There are multiple ways for how entities can affect each other and which solution would work best depends on the problem you are trying to solve.