Issue #22 resolved

Add concept of owner to entities and components

Michael Ludwig
repo owner created an issue

The owner can be another component or entity. When the owner is removed from the system, all owned components are removed as well.

Entities and components created manually by the programmer do not have any owner, and so their lifetime is left to the programmer.

If a task adds entities or components to another entity, those new items are owned by the triggering component (i.e. ParticleSystem owns its automatically generated Renderable).

Additionally, there should be a @Required annotation that can be applied to ComponentData definitions. When a component is added, any required components are added as well, with the new component as an owner. This makes it easy to specify most dependencies between components.

Comments (2)

  1. Michael Ludwig reporter

    There a number of behaviors that need to be decided on:

    1. Can both entities and components be owners and be owned themselves?
    2. Can an owner own multiple objects?
    3. Can you specify the inverse owner relationship (e.g. say this component is owned by, instead of this component owns)?
    4. What happens when you remove an object that is owned? Does it fail, do nothing, return a success flag?

    With regards to the first, I think there should be an Ownable interface that both Component and Entity implement. It has methods to get and set its owner. The owner can be any object, and owners can define how to treat their owned objects (i.e. Entity and Component will remove them after they are removed, but that doesn't restrict someone from using a task/game object as an owner).

    With the above API, it's clear that an object can own multiple Ownables, but each Ownable can only be owned by one parent. The API also operates on the inverse relationship, so it makes it easy to add new components that are dependent on existing components on an entity.

    Since remove() already returns a success boolean, I think it should be updated to only succeed if the component has a null owner.

  2. Log in to comment