Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Best way to handle component hierarchy

Open PranavSK opened this issue 5 years ago • 1 comments

Hi,

I have a question regarding maintaining hierarchy of components.

At present I handle the hierarchy with respect to entities. I have an Id component with an int value and a Parent component with an int value. I use the PrimaryEntityIndex attribute to help find the parent entity from Parent component value.

This works but after some thought I realized it would be beneficial to have this parent child relationship with respect to components. This can be very versatile as the same entity can be used in multiple relationships in multiple contexts etc., Currently with Entitas I am struggling to find an approach for this.

Using a reference to the parent/child component cannot work since the components are recycled when the value is changed via ReplaceComponent method. Any suggestions would be helpful. Thanks.

With Best Regards, Pranav SK

PranavSK avatar Dec 21 '18 11:12 PranavSK

Hi, this is the thing I would like to avoid if possible. In practice, I consider data as a "flat" structure in the ECS, so they can be batched/multi-threaded easily. ECS is an architecture other than ComponentSystem, thus "Thinking in ECS" might be helpful. Indeed, there is some relationship like "Pet" in games, you can use the index to fetch them and it's not going to be a big problem in general.

zhuchun avatar Jan 04 '19 02:01 zhuchun