Strata - v1.4.10
    Preparing search index...

    Function findEntityById

    • Finds an entity by its ID.

      O(1) lookup when using StrataWorld's internal Map, falls back to O(n) linear search for backwards compatibility. Always use this over manual iteration.

      Type Parameters

      Parameters

      • world: StrataWorld<T>

        The Strata world.

      • id: string

        The entity ID to find.

      Returns T | undefined

      The entity if found, undefined otherwise.

      const player = world.spawn({ health: 100 });
      const playerId = player.id!;

      // Later, find by ID
      const found = findEntityById(world, playerId);
      if (found) {
      console.log('Player health:', found.health);
      }
      // Store ID in a component for cross-entity references
      interface Follower {
      targetId: string;
      }

      for (const follower of world.query('follower', 'targetId')) {
      const target = findEntityById(world, follower.targetId);
      if (target) {
      // Follow target's position
      }
      }