Vixen
caa30e12
csharp
public interface IAgentAction

The one thing all three planners choose. A behaviour-tree task, a utility action and a GOAP action are each this, which is what lets one project write MoveToTask once and get it in all three.

Read the guide page for this →

Remarks

⚠ The action does not own its state, and the interface is shaped to make that impossible to get wrong. One action object is shared by every agent running the asset it belongs to, so a field on the action is a field a thousand agents write to. That is the mistake every hand-rolled behaviour tree makes; it is invisible until the second agent exists, and it produces the bug where two guards share one patrol index. Taking the span is the only arrangement in which the mistake cannot be made.

The span is a window into the agent's memory block, sized by AgentActionRegistry.Register's stateSize and zeroed before Start. Put a struct in it with MemoryMarshal.AsRef<T>(state); a reference does not go in it, and a node that needs one stores an Entity or an AssetId, both of which are values.

Implementations must be safe to call from several agents at once. Chunks are stepped in parallel, so an action that touches anything outside its span and its context's own agent is a data race the scheduler cannot see.

Methods (3)

  • void Start(in AgentContext context, Span<byte> state)

    Begins. Called once before the first Tick, on a zeroed span.

  • ActionStatus Tick(in AgentContext context, Span<byte> state, float delta)

    Advances it.

  • void Abort(in AgentContext context, Span<byte> state)

    Stops it early. The span is zeroed afterwards; this is for what is outside it.

Used by (38)

  • AgentActionRegistryVixen.Ai
  • AiSystemVixen.Ai
  • AlwaysFailsVixen.Ai.Tests
  • AlwaysRunsVixen.Ai.Tests
  • BehaviorTaskBuildVixen.Ai
  • BehaviorTreeInstanceVixen.Ai
  • BuildStateVixen.Ai
  • ClearBlackboardValueTaskVixen.Ai
  • CountingVixen.Ai.Tests
  • CountingActionVixen.Ai.Tests
  • EntryVixen.Ai
  • FinishWithTaskVixen.Ai
  • FinishingVixen.Ai.Tests
  • FinishingActionVixen.Ai.Tests
  • IdleVixen.Ai.Diagnostics.Tests
  • IdleVixen.Ai.Tests
  • IdlingVixen.Ai.Nodes.Tests
  • KeyWritingTaskVixen.Ai.Tests
  • LogTaskVixen.Ai
  • MakeNoiseTaskVixen.Ai.Perception
  • MoveDirectlyTowardTaskVixen.Ai.Nodes
  • MoveToTaskVixen.Ai.Nodes
  • PatrolTaskVixen.Ai.Nodes
  • PlayAnimationTaskVixen.Ai.Nodes
  • PlaySoundTaskVixen.Ai.Nodes
  • ProbeTaskVixen.Ai.Tests
  • RotateTowardTaskVixen.Ai.Nodes
  • RunQueryTaskVixen.Ai.Nodes
  • RunSubtreeDynamicTaskVixen.Ai
  • RunUtilitySetTaskVixen.Ai
  • SeamTestsVixen.Ai.Nodes.Tests
  • SetBlackboardValueTaskVixen.Ai
  • StandingVixen.Ai.Tests
  • SucceedsEveryFewTicksVixen.Ai.Tests
  • TickCountingActionVixen.Ai.Tests
  • WaitBlackboardTimeTaskVixen.Ai
  • WaitTaskVixen.Ai
  • IdleVixen.Editor.AssetEditors.Tests