Skip to content

Components

acoox edited this page Apr 22, 2021 · 5 revisions

First see Entity Component System and Entities.

A component contains a piece of functionality that can be used across entities. Some examples include:

  • InputComponent: Creates user input events on the entity, to which other components can react.
  • RenderComponent: Renders the entity to the screen.
  • CombatComponent: Gives health and attack stats to an entity.
  • AITaskComponent: Runs AI tasks on an NPC such as enemies.
  • TerrainComponent: Renders the map terrain on the screen.

All components should extend from the base Component class.

Component Lifecycle

A component's lifecycle is the nearly same as the entity to which it is attached (See Entity Lifecycle). When an entity is created, updated, or disposed, then create(), update(), and dispose() are called on each component attached to that entity.

Note: One important exception is enabling/disabling. When an entity is disabled, its components are not updated. However, components can be independently enabled/disabled as well. By disabling one or more components while keeping the entity enabled, we can modify that entity's behaviour during gameplay.

Clone this wiki locally