Strata - v1.4.10
    Preparing search index...

    Function addComponent

    • Adds a component to an existing entity.

      Dynamically adds a component at runtime. The entity will immediately match any queries that require this component. Uses Miniplex's reactive system.

      Type Parameters

      • T extends BaseEntity
      • K extends string | number | symbol

      Parameters

      • world: StrataWorld<T>

        The Strata world.

      • entity: T

        The entity to modify.

      • component: K

        The component key to add.

      • value: T[K]

        The component value.

      Returns void

      const entity = world.spawn({ position: { x: 0, y: 0, z: 0 } });

      // Add health component later
      addComponent(world, entity, 'health', 100);

      // Now entity matches queries for 'health'
      for (const e of world.query('health')) {
      console.log(e.health); // entity is included
      }