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.
The Strata world.
The entity ID to find.
The entity if found, undefined otherwise.
const player = world.spawn({ health: 100 });const playerId = player.id!;// Later, find by IDconst found = findEntityById(world, playerId);if (found) { console.log('Player health:', found.health);} Copy
const player = world.spawn({ health: 100 });const playerId = player.id!;// Later, find by IDconst found = findEntityById(world, playerId);if (found) { console.log('Player health:', found.health);}
// Store ID in a component for cross-entity referencesinterface Follower { targetId: string;}for (const follower of world.query('follower', 'targetId')) { const target = findEntityById(world, follower.targetId); if (target) { // Follow target's position }} Copy
// Store ID in a component for cross-entity referencesinterface Follower { targetId: string;}for (const follower of world.query('follower', 'targetId')) { const target = findEntityById(world, follower.targetId); if (target) { // Follow target's position }}
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.