Goal Oriented Action Planning
Engine: Unreal Engine 4
Development Time: 2 weeks
My GOAP AI System consists of 5 classes:
The GAction class is a class that every action the AI can take inherits from. It contains to information about duration of the task, task location, as well as prerequisites for the task and the result of completing that task.
The GActor class is an AI Controller class which keeps track of the AIs goal and the current list of tasks it has to complete to reach it's goal.
The GoapPlanner class is an actor class that has to be in the world, every AI that uses the GOAP system can use this class to make their plan.
The WorldStateManager class keeps track of different events in the world, such as in this case if a canon can be fired, the AI uses this to check if it can complete the task.
The GInventory class holds different objects that the AI might need for their tasks.
I wanted to make this system as modular as possible, because of this I chose to make each action into an actor component that the developer would place on the AI Character. These can then be modified with preconditions and effects. The action has two override functions which are implemented in blueprint: bool PrePerform() and bool PostPerform().
The GActor class is the AI Controller that each AI character has to utilize in order to use the GOAP system. This class checks if the current action has been completed, if the task is completed it will move on to the next or make a new plan depending on the goal. This class holds two important functions: Init and Update.
Init is called in the beginning of the game, this function gets all the possible tasks and gets different managers.
Update Is called on a timer from blueprint. It updates the characters beliefs, makes sure the character has tasks to act upon, and if needed makes a new plan.
The GPlanner class is the class that holds the main planning algorithm. It holds two important functions: Plan and BuildGraph.
Plan is used for putting together the plan, it creates a starting node and then starts building a graph from that node, when it has a path towards the goal it compares costs to get the cheapest one.
BuildGraph gets the best path towards the goal, it compares each nodes effects to find its way from the starting node to the goal node.
The WorldStateManager keeps track of different states in the world that the AI might need to know and react upon. In my current example it is used for telling the AI that there are trees that can be cut down. Since the AIs goal is to gather wood it will act when there are trees to cut down.