AgentPath
Lightweight waypoint path defined by child transforms. Provides indexed access to world-space positions and draws debug lines between waypoints in the Scene view when selected.
Definition
Namespace: Paragon.Townskeep.AgentSystem
Assembly: Townskeep.dll
public class AgentPath : MonoBehaviourInheritance: MonoBehaviour → AgentPath
Remarks
AgentPath is a purely data-driven path definition. It has no runtime behavior — it simply exposes the world-space positions of its child transforms via an indexer and a count property.
How It Works
Each child Transform of the AgentPath GameObject represents a waypoint. The path order is determined by the sibling index of the children (as returned by transform.GetChild(index)). Moving, adding, or reordering children in the hierarchy changes the path.
Scene Visualization
When the AgentPath GameObject is selected in the Scene view, OnDrawGizmosSelected() draws lines between consecutive waypoints, providing a visual preview of the path route.
Intended Usage
AgentPath is consumed by FollowPathAction, which iterates from index 0 to Size - 1 and moves the agent to each waypoint position sequentially.
Quick Lookup
Get waypoint count
path.Size
Get waypoint position
path[index]
Create a path
Add an AgentPath component, create child GameObjects as waypoints
Reorder waypoints
Reorder child GameObjects in the hierarchy
Properties
Size
The number of waypoints in the path (equal to transform.childCount).
this[int index] (Indexer)
Returns the world-space position of the waypoint at the given index.
index
int
Waypoint index (0 to Size - 1)
Returns: Vector3 — the world-space position of the child transform at that index.
No bounds checking — Accessing an index outside [0, Size - 1] will throw an ArgumentOutOfRangeException from transform.GetChild().
Common Pitfalls
Path depends on child transform positions
Waypoint positions are read from transform.GetChild(index).position at access time, not cached. If a child transform moves at runtime, the path changes dynamically. This is typically not intended for AI patrol routes.
Empty path (no children)
If the AgentPath has no child transforms, Size returns 0. FollowPathAction will iterate zero times and complete immediately — this is safe but may indicate a misconfiguration.
Gizmos only visible when selected
Path lines are drawn in OnDrawGizmosSelected(), not OnDrawGizmos(). The path is only visible when the AgentPath GameObject is selected in the hierarchy. To see all paths at once, switch to OnDrawGizmos().
Examples
Hierarchy Setup
Accessing Waypoints in Code
Using with FollowPathAction
See Also
FollowPathAction — action that sequentially follows this path
Path Overview — subsystem overview
Agent System Overview — full system architecture
Last updated