Engine > Managers > Entity Manager

Manages entity creation and spatial/player indexing. Acts as the single access point for spawning and removing entities from GameState, while maintaining lookup caches by tile and by player. All entity spawning and removal flows through here rather than touching state directly.

initCaches

Initialises lookup caches from existing state. Called once after GameState is populated, primarily needed when loading a saved game.

addUnit

Creates and registers a unit entity from the given config, merging asset and constant data. Returns null if the target tile is occupied.

#getPlayerColor

Returns the color key assigned to the given player, falling back to the settings default if the player is not yet registered.

getUnits

Returns all unit entities owned by the given player.

getEntityAt

Returns the entity at the given tile coordinates, or null if unoccupied.

isTileOccupied

Returns true if a tile is occupied by any entity.

#tileKey

Encodes (x, y) tile coordinates into a single integer key for the tile cache.

#addEntity

Registers an entity in GameState and both lookup caches (by tile and by player).

moveEntity

Moves an entity to a new tile, updating its coordinates and re-keying the tile cache. Does not validate occupancy - caller must ensure the target tile is free before calling.

removeEntity

Removes an entity from GameState and both lookup caches (by tile and by player).




© Gamesanova 2026