Groups in an EntitySystem

78 views
Skip to first unread message

That Guy

unread,
May 3, 2015, 3:35:06 AM5/3/15
to ash-fr...@googlegroups.com
I keep running into this issue, I may have posted a question about it before tbh, but I still don't have a good solution.

I have some base entities, e.g. some fish.
Each fish is a member of a "school" (group) of fish.
Each school is an entity in its own right.

Now, the problem is that many of the systems that work on the schools, need access to the data that is contained in the individual fish entities.

The one hack I use so far is creating a school-component that contains an array of the individual fish components needed by the school-system.
This is not pretty, doesn't feel right, and as far as I can see it kills the "modularity" benefit of using an ECS. A fish now must have a specified component or the school system won't compile, as opposed to just not processing the entity.


Is there maybe a better way of doing this?

Damion Murray

unread,
May 3, 2015, 8:56:43 AM5/3/15
to ash-fr...@googlegroups.com
Here's an alternative approach the problem. Instead of making 'a school of fish' an entity in of itself, create a school component that identifies which school/grouping a fish entity belongs to. Then create a system that requires that component (as well as the other properties in question). Then the system will loop over all fish entities...partition them based on their school components and perform other operations accordingly.

Damion Murray

unread,
May 3, 2015, 9:02:22 AM5/3/15
to ash-fr...@googlegroups.com
Try to avoid making any kind of grouping a specific entity.


On Sunday, May 3, 2015 at 3:35:06 AM UTC-4, That Guy wrote:
Message has been deleted

That Guy

unread,
May 5, 2015, 11:24:43 AM5/5/15
to ash-fr...@googlegroups.com
Thanks for the suggestion, but I don't think it would work in my case. There is simply too much logic needed at the group level, i really need specific systems for it.

Damion Murray

unread,
May 5, 2015, 12:46:59 PM5/5/15
to ash-fr...@googlegroups.com
You can have specific systems that iterate over the same set of fish entities but which perform group level operations based on the 'school' a fish entity belongs to.
It seems like excess work to create an entity for a given 'school' of fish where a component identifying said 'group' would suffice.
Can you provide any concrete details about the project? Maybe if we have a better grasp of the problem domain we can be of more help.

That Guy

unread,
May 6, 2015, 7:37:12 AM5/6/15
to ash-fr...@googlegroups.com
Ah, an example...

The group has a spatial, a velocity and a path component. The path system updates the velocity according to the way-points in the path, and in turn the spatial component is updated.

Doing all this in a system that updates nodes belonging to members of the group seems... strange me?
Reply all
Reply to author
Forward
0 new messages