GrabItemAction
Agent action that picks up an item by triggering its CarryInteraction. Resolves the item's Interactable component and uses the character's Interactor to start carrying it.
Definition
Namespace: Paragon.Townskeep.AgentSystem
Assembly: Townskeep.dll
public class GrabItemAction : AgentActionInheritance: Action → AgentAction → GrabItemAction
Remarks
GrabItemAction is a synchronous action (returns Task.CompletedTask) that initiates a CarryInteraction on a target item. It bridges the agent AI system with the Interaction System — the agent "grabs" an item by interacting with it through the same interactor system that players use.
Execution Flow
Variable Binding
The item field is marked [Variable], meaning it is typically set by a preceding action in the sequence (e.g., WanderAction sets "Item" when it finds a shop item to purchase).
Quick Lookup
Grab an item via AI
Add GrabItemAction to an ActionSequence; ensure "Item" variable is set
Check interaction result
The CarryInteraction output is discarded (out _)
Fields
item
Item
[Variable] private
The target item to grab; bound from sequence variables
interactable
Interactable
private
Cached Interactable component from the item
Methods
OnBegin
If item is not null, caches its Interactable component for use in OnExecute().
OnExecute
Attempts to start a CarryInteraction with the item's Interactable. Returns synchronously — no frame waiting.
Returns: Task.CompletedTask — this action completes instantly.
Common Pitfalls
Null item is silently ignored
If the item variable is not set (null), OnBegin() skips the interactable lookup, and OnExecute() returns immediately without error. Ensure the preceding action in the sequence sets the "Item" variable.
Double Interactor access
The code accesses character.Interactor.Interactor — the first .Interactor is the CharacterInteractor component, the second is its inner Interactor object. This is the expected pattern for accessing the interaction system through a character.
CarryInteraction result is discarded
TryInteractWith outputs a CarryInteraction instance, but it is discarded (out _). The action does not verify whether the interaction actually started. If the interaction fails (e.g., conditions not met), the agent proceeds silently.
Synchronous execution
Unlike most agent actions, GrabItemAction returns Task.CompletedTask rather than using await. The grab is initiated instantly in a single frame. The carry state is managed by the interaction system, not this action.
See Also
AgentAction — abstract base with agent context
LookAtAction — another synchronous action often used before grabbing
TradeItemAction — releases the carried item for trading
Actions Overview — subsystem architecture
Last updated