Entitas
Entitas copied to clipboard
Best way to handle component hierarchy
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
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.