How it works
Architecture
Section titled “Architecture” +---------------------------+ PlayerCameraManager -->| UHorrorGazeSubsystem | one per world (resolved once/frame) | FTSTicker driver | +-------------+-------------+ | DriveTick(dt, camLoc, camRot) +-------------------------+-------------------------+ v v v +--------------------+ +--------------------+ +--------------------+ | GazeTrackerComp A | | GazeTrackerComp B | | GazeTrackerComp C | | poll @ PollingHz | | poll @ PollingHz | | poll @ PollingHz | | dwell/away timers | | dwell/away timers | | dwell/away timers | +--------------------+ +--------------------+ +--------------------+UHorrorGazeSubsystem is a UWorldSubsystem. It registers one FTSTicker delegate that runs every frame on the game thread. Each tick it:
- Checks the global enable state (Project Settings, runtime flag, console override). If gaze tracking is off it returns at once, so a disabled system does no work.
- Drops registered trackers whose owning actor has been destroyed.
- Returns early if no trackers are registered. Levels that don’t use the system pay nothing.
- Resolves the player viewpoint once from
PlayerCameraManager(player 0). That is the smoothed, blended pose the player actually sees, including camera shake and camera-mode blends. - Calls
DriveTickon every registeredUHorrorGazeTrackerComponentwith that shared viewpoint.
Components register in BeginPlay and unregister in EndPlay. There is nothing to wire up.
Evaluation pipeline
Section titled “Evaluation pipeline”Each component accumulates frame time and runs a visibility evaluation only when its own PollingHz interval has elapsed (15 Hz by default). An evaluation runs three rejects, cheapest first:
| Step | Test | Cost | Reject when |
|---|---|---|---|
| 1 | Distance | one vector length | distance from camera to the actor’s bounds origin exceeds MaxTrackDistance |
| 2 | View cone | one dot product | angle between camera forward and the direction to the bounds origin exceeds ViewAngleDegrees (skipped when bUseViewAngle is off) |
| 3 | Line of sight | N line traces | every sample point is blocked. One clear trace means visible |
Steps 1 and 2 always use the actor’s bounds origin. SampleSource only decides where the step 3 traces go.
Traces run on TraceChannel (default Visibility) with simple collision, from the camera to each sample point. The traces ignore the tracked actor itself, the local player’s pawn (when bIgnoreLocalPlayerPawn is on) and any AdditionalIgnoredActors.
State machine and gating
Section titled “State machine and gating”Raw visibility is never exposed directly. It passes through two timers:
raw visible for raw hidden for >= MinDwellTimeSeconds >= MinAwayTimeSeconds NEVER SEEN -----------------------> VISIBLE ----------------------> HIDDEN ^ | | raw visible for | +---- >= MinDwellTimeSeconds -----+- Entering VISIBLE increments
SeenCountand setsbHasBeenSeenBefore. It then broadcastsOnFirstGazeStartedon the first sighting orOnGazeReturnedon every later one, andOnGazeStartedlast. - Leaving VISIBLE resets
CurrentVisibleDurationto zero and broadcastsOnGazeEnded.
The dwell/away timers advance every frame, not only on evaluation frames, so a threshold expires on the exact frame it is due rather than on the next poll.
Timing
Section titled “Timing”- The driver runs on the engine’s core ticker with application delta time. Global time dilation doesn’t affect the dwell/away timers, and they keep running while the game is paused with Set Game Paused. For pause menus, inventories and cutscenes, call Set Global Gaze Enabled (false) on the subsystem.
PollingHzcaps how often a tracker evaluates and doesn’t depend on frame rate. The same value behaves the same on a 30 fps console and a 240 fps PC.
Sampling modes
Section titled “Sampling modes”SampleSource decides where the line traces aim.
| Mode | Traces to | Best for |
|---|---|---|
| Actor Bounds (default) | The actor’s bounds origin, plus the 8 box corners when Sample Bounds Corners is on. The bounds include every component on the actor, colliding or not. | Props, doors, pickups: anything whose bounds hug its mesh. |
| Named Component Bounds | The bounds of one primitive component, found by Sample Component Name. Corners as above. | Actors with extra components (particles, lights, trigger volumes) you don’t want counted as the target. |
| Mesh Sockets | Each socket in Sample Socket Names, on the mesh found by Sample Mesh Component Name. Missing sockets are skipped. | Characters and creatures: head, chest, pelvis. Any actor where “seen” means a specific part is seen. |
Sample Bounds Corners is the trade-off for the two bounds modes. With it on, a target counts as visible when any corner pokes out from cover. With it off, only the centre counts: one trace per evaluation, and a target with only an edge exposed reads as hidden.
On characters, use Mesh Sockets. Troubleshooting explains why Actor Bounds misbehaves on characters with trailing particle systems.
Hidden-location queries
Section titled “Hidden-location queries”Sometimes the question is about a spot, not an actor: is it safe to put something there? Both queries live on the subsystem.
The test
Section titled “The test”IsWorldLocationHiddenFromPlayer runs two stages, cheapest first:
- View cone. A location outside
ConservativeViewHalfAngleDegfrom camera forward is behind or beside the player and counts as hidden, with no trace spent. Most “the player is looking elsewhere” cases end here. - Line of sight. Traces from the camera to the location and to six points around it, ±
SampleRadiuson each axis, for seven traces in total.SampleRadius0 means a single trace. The location is hidden only if every trace is blocked.
The local player’s pawn is always ignored, plus anything you pass in IgnoreActors.
With no camera at all (main menu, loading screen, level transition) both queries return hidden. With no observer, scripted logic gets through transitions instead of stalling.
The helper
Section titled “The helper”FindHiddenRandomOffset covers the common case. It picks random offsets within the X/Y/Z ranges around the actor, tests each candidate, and returns the first one the player can’t see. It adds the actor to the ignore list for you, because otherwise its own mesh would block traces to the spot it is about to move to.
Keep Max Attempts at 10–20; the player can’t see most of the world at any moment. If every candidate is visible it returns false and leaves the location unchanged. You then decide whether to skip this time or retry on the next OnGazeEnded.
Performance
Section titled “Performance”Fixed cost per world per frame: one PlayerCameraManager lookup and one loop over registered trackers that only advances timers. A tracker that is out of range or outside the view cone costs nothing more.
Per tracker, per evaluation (at PollingHz):
- One
GetActorBoundscall. - One distance check and one dot product.
- Only if both pass: the line traces. 9 for a bounds source with corners, 1 without, or one per socket.
traces/s = (trackers in range AND in cone) × samples per tracker × PollingHzFifty props all in view, bounds with corners, at 15 Hz: 50 × 9 × 15 = 6,750 simple traces per second, about 110 per frame at 60 fps. That load is fine, and in practice only a handful of trackers pass the cone test at once.
To spend less:
- Lower
MaxTrackDistance. It is the first and cheapest reject. Set it to the distance the mechanic reads at. - Lower
PollingHzfor slow or distant targets. 5–10 Hz is often enough for props. - Turn off
SampleBoundsCornerson small props where centre-only is accurate enough. - Use sockets sparingly. Two or three sockets on a character beat nine bounds corners, and are more accurate.
- Disable trackers you don’t need with Set Tracking Enabled (false), or pause everything with Set Global Gaze Enabled (false) when the player isn’t in the world.
Multiplayer
Section titled “Multiplayer”The gaze query is local. It resolves player 0’s camera on the machine it runs on and answers for that player only.
- The subsystem exists in every world, so it runs on clients and on a listen server (where player 0 is the host).
- On a dedicated server there is no
PlayerCameraManager. The driver finds no viewpoint, evaluates nothing and fires no events, and trackers stay in NEVER SEEN. - Gaze events don’t replicate. Run gaze-driven logic on the owning client and replicate the result (the new location, the swapped mesh) through your normal replication path.
- Split-screen and multiple local players aren’t supported in this version.