AgentAction
Abstract base class for all agent-specific actions. Extends the core Action class with pre-cached references to the owning Agent, its possessed Character, and the NavMeshAgent — providing a rich context for AI behavior implementations.
Definition
Namespace: Paragon.Townskeep.AgentSystem
Assembly: Townskeep.dll
public abstract class AgentAction : ActionInheritance: Action → AgentAction
Remarks
AgentAction is the bridge between Paragon's generic Action system and the Townskeep agent AI. It adds an Initialize() method that injects agent-specific context, which all concrete agent actions can use in their OnBegin() / OnExecute() implementations.
Initialization Flow
AgentAction.Initialize() is called by Agent.DoAI() at the start of each AI loop iteration, before the ActionSequence executes. This means context references are refreshed every loop cycle.
Context Fields
The four protected fields provide everything an agent action needs:
agent
Agent
Passed directly
Access to the agent brain, NavMeshAgent, and possession system
sequence
ActionSequence
Passed directly
The containing sequence (for variable sharing between actions)
character
Character
agent.Character
The possessed character — motor, controller, inventory, etc.
navMeshAgent
NavMeshAgent
agent.NavMeshAgent
Unity NavMesh pathfinding (path calculation only, updatePosition = false)
Quick Lookup
Create a new agent action
Subclass AgentAction, override OnExecute()
Access the character motor
character.Motor
Access the character controller
character.Controller
Calculate a NavMesh path
navMeshAgent.SetDestination(target)
Access the owning agent
agent
Share variables across actions
Use sequence.SetVariable<T>() / sequence.GetVariable<T>()
Fields
agent
Agent
protected
The owning agent
sequence
ActionSequence
protected
The containing action sequence
character
Character
protected
The possessed character
navMeshAgent
NavMeshAgent
protected
Unity NavMesh agent for pathfinding
Methods
Initialize
Injects agent context into the action. Called by Agent.DoAI() before each sequence execution.
agent
Agent
The owning agent
sequence
ActionSequence
The action sequence containing this action
Behavior:
Stores
agentandsequencereferencesCaches
agent.Character→characterCaches
agent.NavMeshAgent→navMeshAgent
Extension Points
Required Overrides
OnExecute()
Task
Core AI logic — inherited from Action
Optional Overrides
OnBegin()
void
Setup before execution (create sub-actions, resolve targets)
OnComplete()
void
Success-path cleanup
OnCancel()
void
Cancellation-path cleanup
OnEnd()
void
Final cleanup regardless of outcome
Implementation Requirements
When subclassing AgentAction, you MUST:
Override
OnExecute()and return aTaskUse
Yieldmethods for frame-based waiting (integrates with cancellation)
You SHOULD:
Create sub-actions (like
MoveToTargetAction) inOnBegin(), not inOnExecute()Call
Initialize()on sub-actions before using themUse
character.Controllerorcharacter.Motorfor movement, notnavMeshAgent.Move()Mark configurable fields with
[Variable]for Inspector/sequence variable binding
You SHOULD NOT:
Rely on
navMeshAgent.updatePosition— it isfalse; the NavMesh agent is for path calculation onlyAssume
Initialize()has been called in the constructor — it runs at the start of each AI loop iteration
Common Pitfalls
Initialize() is not called automatically
Unlike CharacterComponent.OnInitialize(), AgentAction.Initialize() must be called explicitly. The Agent.DoAI() loop handles this, but if you create an AgentAction outside the normal AI loop (e.g., as a sub-action), you must call Initialize() yourself.
NavMeshAgent is for path calculation only
navMeshAgent.updatePosition is false. Calling navMeshAgent.Move() or relying on navMeshAgent.nextPosition for automatic movement will not work. Use character.Controller.MoveTo() or character.Motor.MoveTo() instead.
Examples
Minimal Agent Action
Action with Sub-Action
See Also
Agent — the AI brain that initializes and executes agent actions
FollowPathAction — concrete action: follow a waypoint path
GoToStoreAction — concrete action: navigate to a shop table
Action — core abstract action class
Actions Overview — subsystem architecture
Last updated