Perception
A Perceiver scans for the nearest visible PerceptionTarget each frame and writes
the result into a Perception component on the same entity (adding one if the entity has none). A
Perceiver never senses itself. Decisions read Perception; sensing is just ECS data, not a side
channel. The step runs in PreUpdate, in play mode only, so a decision system reads a fresh result
the same frame.

A Perceiver (above) and the Perception it writes (below, off until play).
import { Perceiver, PerceptionTarget, Perception } from 'esengine/ai';
// The hunter senses…cmds.spawn() .insert(Transform, { position: { x: -200, y: 0, z: 0 } }) .insert(Perceiver, { range: 260, fovDegrees: 120 }) .insert(Perception, {}); // written every frame by the perception plugin
// …anything tagged as a target.cmds.spawn() .insert(Transform, { position: { x: 100, y: 0, z: 0 } }) .insert(PerceptionTarget, {});| Component | Field | Default | Description |
|---|---|---|---|
Perceiver |
range |
220 |
Sight range in world pixels. |
fovDegrees |
360 |
Field-of-view cone in degrees, 0–360 (360 = omnidirectional). |
|
facingAxis |
'x' |
Which of the entity’s own axes the cone points down: 'x' is screen-right (a flat scene), '-z' is where an imported 3D model faces. |
|
losLayers |
0 |
3D only: physics layers the line-of-sight ray may hit (0 = every layer). |
|
Perception |
visible |
false |
A target is currently seen. |
distance |
0 |
Distance to the seen target. | |
targetX, targetY, targetZ |
0 |
Seen target position, world pixels. | |
dirX, dirY, dirZ |
0 |
Unit direction from observer to target. | |
PerceptionTarget |
(tag) | — | Marks an entity as sensable by Perceivers. |
Sensing is three-dimensional (a flat scene is the case where z is constant), so the
cone and the distance work in a 3D scene too. The FOV cone is oriented by the perceiver’s
Transform rotation along facingAxis. When a physics world is present the sight ray is
cast against it, so walls block sight: the 3D solver is used if the scene has one, otherwise
the 2D one; with neither, sensing is range + cone only. Perception is a
transient, runtime-only component — the plugin rewrites it every frame, so you never
author its values.