Hi. I'm trying to integrate physics engine (Box2D) into my custom game engine based on entity-component-system. When I add physics component to entity, I also need to create appropriate objects in Box2D world. Because Box2D has it's own internal world data structure. But components in ECS are just only plain data, they don't have any behavior like OnAttached(), OnDetached(). Instead all the behaviors are implemented in systems. So I need to somehow know if component is newly added to entity or not in physics system. If it is newly added then create object in Box2D world. For that reason I created XXXCreateInfo components. (For example RigidbodyCreateInfo) And if I need to add rigidbody to entity, I just add RigidbodyCreateInfo with it's properties (mass etc..) to entity. And physics system create rigidbody in box2d world and attach it to entity with Rigidbody component and remove old RigidbodyCreateInfo.
This method works good for adding physics component. But how can I remove them if entity is destroyed? Should ECS has OnAttach, OnDetach events for components? Or can we workaround this problem with only systems?