Interface Component

Components can optionally define these lifecycle methods to respond to assignment and removal to and from entities. These are useful if the component is managing a resource outside of the ECS.

interface Component {
    onAssign: ((entity) => void);
    onRemove: ((entity) => void);
}

Properties

Properties

onAssign: ((entity) => void)

Called when a component is being assigned to an entity with Ecs.assign, passing in the entity it was assigned to.

Type declaration

    • (entity): void
    • Parameters

      • entity: number

      Returns void

onRemove: ((entity) => void)

Called when a component is being removed from an entity with Ecs.remove, passing in the entity it was assigned to. This is also called when the entity is destroyed with Ecs.destroy and all its components are removed.

Type declaration

    • (entity): void
    • Parameters

      • entity: number

      Returns void