AI Framework Design


1 Framework Design


We provide this compact AI framework to show how to use the AI system in Unreal Engine. The design is focus on the following two points.

  • Define a blueprint interface for AI Controller with basic logic functions. For different AI, just implement the interface for its AI controller blueprint.

  • Define a set of basic behavior trees to controll the AI character. The actions or conditions in the behavior only depend on the above blueprint interface.

The advantage of this design is that you don’t need to create too many behavior trees for AI. The purpose of this framework is to handle most of behavior for the specific type of AI, such as AI player in FPS.


2 Program Design


The framework code is located in the following folder.

  • /Game/USGT/Framework/AI

2.1 Behavior Tree


The top behavior tree design is given below.

topbttree


In the top tree, we will detect the AI states and check enemies. Also, determine the AI will move or stop. We have six sub-tree to control AI behavior.

  • BT_AIPlayer_InitTree: Used to initialize the AI character states.

  • BT_AIPlayer_IdleTree: Used to control the AI characters’ behavior when they are in idle state.

  • BT_AIPlayer_MoveTree: Used to control the AI characters’ behavior for moving state.

  • BT_AIPlayer_FightTree: Used to control the AI characters’ behavior when they are in fighting state.

  • BT_AIPlayer_NearDeathTree: Used to control the AI characters’ behavior when they are nearly dead.

  • BT_AIPlayer_DeathTree: Used to control the AI characters’ behavior when they are dead.

In the top tree, we use the following service node to determine which sub-tree running.

treeselection


The function CheckRootStateChanged mentioned in the following section is used for the above selection process.


2.1 AI Controller Interface


Implement following blueprint interface for this compact AI framework.

  • /Game/USGT/Framework/AI/Structure/BP_AIGeneralActionInterface

The AI controller in our project is given below and you can see it as an example.

  • /Game/USGT/Framework/Character/AI_Character/BP_AIController_USG

Implement following interface functions according to your game requirement.

  • CheckRootStateChanged: Check the character state to determine which sub behavior tree will be running.

  • InitStateProcess: Initialize the AI character state.

  • AttackEnemy: Run the action to attack current enemy.

  • IdleActionProcess: The logic running when the AI character is in idle state.

  • ActionBeforeAttack: The action running before attacking enemy.

  • ActionAfterMove: The action running after reaching one target location.

  • UpdateMoveDestination: Update the target moving location.

  • CheckEnemy: Return the enemy for attacking.

  • OnBevTreeModifyAIState: Change the AI state for current AI character and you can cache this state for AI control.

  • ActionOnNearDeath: The action running when the AI character is nearly dead.

  • ActionOnDeath: The action running when the AI character is dead.


3 Development Flow


See “The Usage of AI Framework”.