Companion System

v1.1.0

Navigation & Following

How companions pathfind around obstacles, climb over low walls, and retrace the player's route

How Companions Move

CPS movement is driver-aware. A companion is a GC2 Character, and GC2 Characters move through a swappable driver. Which driver a companion uses decides how it handles obstacles:

Character Controller / Rigidbody driver

Moves in a straight line toward the target. Fine in open space, but it walks into walls — CPS falls back to a lightweight raycast steering that can nudge around a single obstacle, but cannot route around a whole building or find a doorway.

NavMesh Agent driver Recommended

Uses Unity's NavMesh pathfinding with high-quality local avoidance, agent-to-agent separation, and automatic repathing. Companions route correctly around walls, through doorways, and never clump together — at no extra cost to you.

CPS detects the driver automatically. If a companion already uses the NavMesh Agent driver, native pathfinding is used and the raycast fallback is skipped entirely. With Prefer NavMesh (the default), CPS also upgrades companions to the NavMesh driver at spawn when a baked mesh is present.

Obstacle Avoidance Modes

Set project-wide in CompanionSettings → Navigation → Obstacle Avoidance.

ModeBehavior
AutoUse native NavMesh pathfinding when the companion already runs the NavMesh Agent driver; otherwise fall back to raycast steering. Non-invasive — never changes the driver.
Prefer NavMesh DefaultSame as Auto, but also upgrades the companion's Character to the NavMesh Agent driver at spawn when a baked NavMesh is present. Zero-config "it just works".
Raycast OnlyAlways use the legacy raycast steering, even on a NavMesh driver. A back-compat escape hatch.

Breadcrumb Trail Following

Pathing straight to a slot beside the player is a problem around corners: the computed route can differ from the one you actually walked, sometimes ending in a pocket beyond another wall. CPS solves this by recording a breadcrumb trail of where the owner actually walked and having companions follow a point back along that trail — so they retrace your exact route through the same doorway, around the same corner.

Hybrid behavior

  • While the owner moves: companions follow single-file along the breadcrumb trail, staggered so multiple companions form a natural follow-the-leader line.
  • While the owner is at rest: companions fan out into their configured formation (Line / V / Circle) around the owner.

The trail is recorded by the CompanionOwnerAdapter on your player. Tune it there:

SettingDescription
Record TrailEnable breadcrumb recording (on by default).
Trail Sample DistanceDistance the owner must travel before a new breadcrumb is recorded (default 0.35 m).
Trail Max PointsMaximum breadcrumbs kept. Trail length ≈ points × sample distance.
Trail DiscontinuityIf the owner jumps farther than this between samples (teleport/warp), the trail is cleared so companions never path along a bogus segment.
Trail following is automatic when the owner implements the trail interface (the built-in CompanionOwnerAdapter does). A custom owner without it simply falls back to formation-slot following. When the trail is too short (e.g. you just started moving), companions also fall back to the formation slot until enough breadcrumb exists.
With the hybrid model, V and Circle formations apply while the owner is standing still. In motion, companions travel single-file along your trail. This is intentional — it's what keeps the party retracing your route around corners.

Debugging Movement

Two tools show exactly what a companion is doing in Play Mode.

Companion Motor inspector

A live Navigation section shows the active Obstacle Avoidance setting, the current GC2 driver, and the Active Mode (NavMesh Pathfinding / Raycast — Local Avoidance / Raycast — Direct). On the NavMesh driver it also surfaces the agent's path status (Complete / Partial / Invalid), remaining distance, velocity, and an On Link indicator while climbing.

Companion Path Visualizer

Add CompanionPathVisualizer to a companion (or toggle it from the Brain's Behavior Analyzer). The new Follow Trail toggle draws the owner's breadcrumb polyline and the companion's follow target — orange when retracing the trail, cyan when heading to its formation slot. The Brain inspector also shows a live Following Via: Breadcrumb Trail / Formation Slot readout.

Turn on Debug Logging in CompanionSettings to log driver upgrades, link traversal, and fallback teleports to the console.