GOAP Guard AI

Unity (C#) | GOAP Planning | NPC AI | Editor Tools
This project demonstrates a GOAP (Goal-Oriented Action Planning) AI system designed for NPC guard behaviour in Unity. Agents plan actions based on world states, goals, and available actions, allowing them to dynamically adapt their behaviour in response to the environment.
The project also includes custom editor tools to simplify configuration of actions, patrol routes, and guard behaviours.
​
​​​
​
​
​
​
​

Editor tools:
I decided to create editor tools mainly for user experience such as ease of use to edit the system to their liking.
Patrolling Editor
Here is a patrolling waypoint manager that can be created for any guard with a click of a button. The patrol points can be built with a button press and all the developer needs to do is move them where the patrol path needs to be.



Guard ai manager Editor
After creating the simple GUI implementation on patrol points I decided to build an AI manager editor window for users to easily create new guards and customise them to their liking. This is mainly using scriptable objects and changing data through an editor window. When the user creates a new guard with the button it creates a new scriptable object asset with all the details filled in.
​


This is the window that gets opened up after clicking the "Create new guard" button, this is where the users can customise their guard and save it's data.

Goal orientated action planning(GOAP)
The AI uses a Goal-Oriented Action Planning architecture inspired by STRIPS-like planning systems. Agents evaluate world states, action preconditions, and effects to construct a sequence of actions that satisfies their current goal.
​
This allows guards to dynamically select behaviours such as patrolling, investigating, or engaging threats depending on the game state.
​
Here is a screenshot of the current world states that are given to the planner:

Here are the current pre-conditions and effects for the patrolling action:

Here is some code from a patrolling action class that runs a simple patrolling system around points using the way-point manager that can be created from the patrolling action editor button shown above previously:

Current goals that are given to the AI: "guardArea", and "survive":
​

Debugging the Planner
Debugging the GOAP planner was initially difficult because it was hard to visualise which actions were being selected during planning. To address this, I implemented debugging tools that display the current action queue and threat level in real time.
This made it easier to inspect the AI’s decision-making process and identify issues with planning behaviour.
I also created a simple UI debug system that shows the agent’s current action and threat state during gameplay.


AI System Components
This project was designed as a reusable AI guard system for NPC characters. The system includes a range of behaviours and world states that allow agents to dynamically plan actions using GOAP.
The AI evaluates available actions, current world states, and active goals to determine the most appropriate behaviour at runtime.

References:
Orkin, J., n.d. Goal-Oriented Action Planning (GOAP). [online] Alumni.media.mit.edu. Available at: <https://alumni.media.mit.edu/~jorkin/goap.html> [Accessed 7 December 2021].
