0
\$\begingroup\$

Here's the analogy: I have an organism which is composed of cells which can be further composed of a medley of attachments.

What I have currently is a sort of event chain between child/parents to handle attaching and detaching components (which could affect anything along the chain) which doesn't involve ecs at all, they are functions in the entities.

Now I've used event components already (for mouse events on objects). If I wanted the system to be pure, would I create an attach component when I attach components etc? Even then how would I get all the necessary recipients to the system that consumes the component? Is it even worth it to handle it this way instead of a chain of functions? Is there a better way?

\$\endgroup\$
0
\$\begingroup\$

First of all, you dont have to go ECS all the way if you have something that works just as well. AAs you desribe it, your method works. As you have not given any examples on how it really works, i cant say what Problems your way might have: to strong dependencies or slow code or whatever.

If you want to do it the ECS way, i would suggest to have an own attached component, maybe with corresponding attachable component. The attached component could hold the information for the the attachment. Something like current depth of the entity or id of the attachment and the id of the attachment it is attached to.

Now every component that has an attachment or is attached gets this component. The root cell would have depth 0 with id 0. Everything attached to that would get depth 1, everything gets its own id and the connect-to-id would be 0 in this case.

This way, you have basically a tree with an indefinit amount of branches per leaf. This would be easily exandable or made more simple if your restrictions allow that (only one depth, ...)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.