Component

import { Component } from "encompass-ecs";

A Component can be thought of as a collection of data which is attached to an Entity.

Components are active by default and can be deactivated by the Entity they belong to. While inactive, Entities containing the Component will not be tracked by Detectors that track the Component type. This is useful for situations where you may want to temporarily disable a component without destroying information.

Note that the activation status of a Component is unrelated to the activation status of its Entity.

Components should not contain any game logic, but certain side-effect callbacks are available. For example, you could use callbacks to create or destroy bodies in the engine’s physics system.

Defining non-side-effect logic on a Component is an anti-pattern.

Callbacks

Component.on_initialize()

Runs when the Component is added to an Entity. Deprecated.

Component.on_activate()

Runs when the Component is activated.

Component.on_deactivate()

Runs when the Component is deactivated.

Component.on_destroy()

Runs when the Component is removed from an Entity, or when its Entity is destroyed.