-
Notifications
You must be signed in to change notification settings - Fork 22
Runtime Execution
Reasonable Planning AI has two modes of Runtime execution. These modes are RPAI Native and Behavior Trees. Each of these modes may be present within the same project. The decisions of which system to choose should be determined by the AI designers of the project. Each mode is independent of the other. An agent cannot use both systems at the same time without effort invested in supporting two UBrainComponent
components on a single APawn
.
This is the default reference mode of runtime execution within RPAI. It is completely abstracted from the AI Module while also offering full integration via AI Tasks. It can be added to any project at any time. All one does is add an RPAI Brain Component to an AIController
or APawn
.
The RPAI native method of execution is accomplished via the URpaiBrainComponent
component - hereby known as the RPAI Brain. The RPAI Brain is a child of the Unreal Engine UBrainComponent
class. It hooks into the existing UE AI module and game framework via the UBrainComponent::StartLogic(...)
, UBrainComponent::StopLogic(...)
, and UBrainComponent::PauseLogic(...)
virtual functions. The RPAI Brain is also compatible with the AI Task subsystem built into Unreal Engine. This enables a flexible point of integration with other AI systems such as Smart Objects and Environment Query System (EQS).
---
title: RPAI Brain State Machine
---
flowchart TD
Spawned(Pawn Spawned) --> BeginPlay
GameStart(Game Begins) --> BeginPlay
PauseLogic[[Pause Logic]] --> Paused[/Paused is now True/]
UnPauseLogic[[UnPause Logic]] --> UnPaused[/Paused is now False/]
UnPaused --> Tick
BeginPlay[[Begin Play]] --> StartLogic
StartLogic[[Start Logic]] --> Tick
Paused --> Tick
Tick[[Tick Component]] --> IsPaused
Skip --> Tick
IsPaused{Paused?} -- Yes --> Skip(Skip One Tick)
IsPaused -- No --> ReasonGoal
ReasonGoal[[Reason Next Goal]] --> HasNextGoal
HasNextGoal{New Goal?} -- Yes --> PlanGoalActions
HasNextGoal -- No --> Skip
PlanGoalActions[[Plan Action Set for Goal]] --> HasPlan
HasPlan{Any Actions?} -- Yes --> ExecuteNextAction
HasPlan -- No --> Skip
ExecuteAction --> Cancel(On Cancel)
ExecuteAction --> Complete(On Complete)
ExecuteAction(Tick Current Action) -- Not Paused --> ExecuteAction
Cancel --> CancelRemaining{Cancel All?}
CancelRemaining -- No --> ExecuteNextAction{Pop Action?}
CancelRemaining -- Yes --> ReasonGoal
Complete --> ExecuteNextAction
ExecuteNextAction -- No --> Tick
ExecuteNextAction -- Yes --> ExecuteAction
EndPlay[[End Play]] --> StopLogic[[Stop Logic]]
StopLogic --> Paused
Aside from RPAI Native execution, RPAI supports execution within a Behavior Tree. This is accomplished through two separate tasks defined in the plugin and an adapter component assigned to an AIController
.
RPAI is also adapted to work with your existing Behavior trees. This is accomplished through inline definitions of a Reasoner, Planner, Goals, and Actions in two separate task nodes. The two nodes are pictured below:
TODO: Add Pictures
The two nodes are Determine Next Goal and Execute Planned Goal.
This node accepts for configuration a Reasoner and a set of Goals. All are inline defined in the details panel. This node will return success if it outputs a Goal to the given blackboard key. Otherwise it will return failure and your Behavior Tree will move onto the next (right) node.
This node accepts for configuration a Planner and a set of Actions. All are inline defined in the details panel. This node will return success if it completes all planned actions. If it is unable to produce a plan or an action is cancelled that ends all other actions it will move onto the next (right) node.
For a successful execution of the two tasks outlined above, an AIController
must have a URpaiStateBlackboardComponent
assigned. This component is used to configure which values to copy from the Behavior Tree Blackboard into the RPAI state object used for reasoning and planning. It supports copying all base types that Blackboard supports. It is therefore 100% compatible with your existing blackboard configurations.
Now that you are aware of the two modes of execution - RPAI Native and Behavior Trees - learn more about a third component of RPAI. This third component is the data driven framework for building RPAI Behaviors called Composer