Components in Components

75 views
Skip to first unread message

John Nyquist

unread,
Apr 10, 2015, 7:23:19 PM4/10/15
to ash-fr...@googlegroups.com
When it comes to having an component that has a collection of components, is that something that one would want to avoid in ECS? If so, what are some strategies for avoiding? For example, a game where there is a region that is a collection of tiles. The region component having a vector of tile components. If this is not a good way, how would you handle it?

Daniel Krejčí

unread,
Apr 11, 2015, 3:40:45 PM4/11/15
to ash-fr...@googlegroups.com
Well, it is possible I guess, but you would lose ability to use Node for these "inside" components. However one component can hold reference to multiple entities and you can store your components to these. It's not very elaborate answer, I am sure somebody else will come up with better one, but I suppose it gives you basic idea.

Justin Hamilton

unread,
Apr 12, 2015, 5:19:42 PM4/12/15
to ash-fr...@googlegroups.com
Why wouldn't the region in your example be an entity?

Richard

unread,
Apr 13, 2015, 4:30:55 PM4/13/15
to ash-fr...@googlegroups.com
John

It's only a component if it's added to an entity as a component, using Entity.add(). What you're describing does not sound like a collection of components, it sounds like a collection of data objects. There's no problem with a component containing a collection of data objects.

Richard

Damion Murray

unread,
Apr 14, 2015, 6:42:53 PM4/14/15
to ash-fr...@googlegroups.com
That's precisely what I was thinking. Components don't have to represent the smallest unit of data, you can get more granular and have data objects (or more formally 'value' objects) that you can store as collections.

Daniel Krejčí

unread,
Apr 15, 2015, 12:24:11 AM4/15/15
to ash-fr...@googlegroups.com
Don't forget that you have to keep in mind a matter of serialization. Once the components aren't just shallow units, it gets complicated there, but still manageable I guess.

John Nyquist

unread,
Apr 19, 2015, 5:00:07 PM4/19/15
to ash-fr...@googlegroups.com
Good question!  :-)

John Nyquist

unread,
Apr 19, 2015, 5:02:18 PM4/19/15
to ash-fr...@googlegroups.com
"It's only a component if it's added to an entity as a component", which relates to Justin's question above. Thanks!
Reply all
Reply to author
Forward
0 new messages