FollowPathAction
Agent action that sequentially moves the character through all waypoints in an AgentPath. Creates a MoveToTargetAction sub-action and executes it for each waypoint in order.
Definition
Namespace: Paragon.Townskeep.AgentSystem
Assembly: Townskeep.dll
public class FollowPathAction : AgentActionInheritance: Action → AgentAction → FollowPathAction
Remarks
FollowPathAction is a higher-order action that composes MoveToTargetAction to visit each waypoint in an AgentPath. The path is bound via the [Variable] attribute, making it configurable from the Inspector or through the action variable system.
Execution Flow
OnBegin — Creates a new
MoveToTargetActionand initializes it with the agent contextOnExecute — Iterates from index
0topath.Size - 1:Sets the
MoveToTargetAction's target topath[i](child transform position)Awaits
moveAction.ExecuteAsync()— the character navigates to the waypoint
Completes when all waypoints have been visited
The same MoveToTargetAction instance is reused for all waypoints — only the target position is updated each iteration.
Quick Lookup
Assign a path
Set the path variable via Inspector or action.SetVariable("path", agentPath)
Follow the path
await followPathAction.ExecuteAsync()
Fields
path
AgentPath
[Variable] private
The waypoint path to follow
Extension Points
This is a concrete (non-abstract) action. Override lifecycle hooks from Action if subclassing:
OnBegin()
Creates and initializes the MoveToTargetAction sub-action
OnExecute()
Iterates waypoints and awaits movement to each one
Common Pitfalls
Path variable must be set before execution
The path field is marked [Variable] but has no default value. If it is null when OnExecute() runs, path.Size will throw a NullReferenceException.
Sub-action is initialized in OnBegin, not OnExecute
The MoveToTargetAction is created in OnBegin() and reused across all waypoints. If OnBegin() is skipped (which doesn't happen in normal flow), moveAction will be null.
No looping or ping-pong
The action visits each waypoint once in index order (0 → Size - 1) and then completes. To loop the path continuously, place this action inside a repeating ActionSequence.
Cancellation between waypoints
Because each waypoint is an await moveAction.ExecuteAsync(), cancelling the FollowPathAction will cancel the current MoveToTargetAction at its next yield point. The character will stop between waypoints, not snap to the next one.
Examples
Inspector Setup
Add
FollowPathActionto an agent'sActionSequencein the InspectorCreate a GameObject with an
AgentPathcomponentAdd child GameObjects as waypoints (their positions define the path)
Assign the
AgentPathto thepathvariable
Programmatic Usage
See Also
AgentAction — abstract base with agent context
AgentPath — waypoint path definition
GoToStoreAction — another concrete agent action
Actions Overview — subsystem architecture
Last updated