Skip to content

How it works

+---------------------------+
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:

  1. 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.
  2. Drops registered trackers whose owning actor has been destroyed.
  3. Returns early if no trackers are registered. Levels that don’t use the system pay nothing.
  4. 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.
  5. Calls DriveTick on every registered UHorrorGazeTrackerComponent with that shared viewpoint.

Components register in BeginPlay and unregister in EndPlay. There is nothing to wire up.

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.

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 SeenCount and sets bHasBeenSeenBefore. It then broadcasts OnFirstGazeStarted on the first sighting or OnGazeReturned on every later one, and OnGazeStarted last.
  • Leaving VISIBLE resets CurrentVisibleDuration to zero and broadcasts OnGazeEnded.

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.

  • 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.
  • PollingHz caps 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.

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.

Sometimes the question is about a spot, not an actor: is it safe to put something there? Both queries live on the subsystem.

IsWorldLocationHiddenFromPlayer runs two stages, cheapest first:

  1. View cone. A location outside ConservativeViewHalfAngleDeg from 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.
  2. Line of sight. Traces from the camera to the location and to six points around it, ±SampleRadius on each axis, for seven traces in total. SampleRadius 0 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.

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.

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 GetActorBounds call.
  • 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 × PollingHz

Fifty 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 PollingHz for slow or distant targets. 5–10 Hz is often enough for props.
  • Turn off SampleBoundsCorners on 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.

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.