GOAP: AI plugin for Unreal Engine 5
Context
As part of the Artificial Intelligence Applied to Video Games course in the Master’s in Video Game Development at the University of Sherbrooke (DDJV) , taught by Carle Côté , we were tasked in pairs with researching and presenting a specific AI concept. We chose to study Goal-Oriented Action Planning (GOAP) and Hierarchical Task Networks (HTN). To demonstrate the practical application of our research, we developed a custom GOAP plugin for Unreal Engine 5.
Teams Members:
What is GOAP?
Goal-Oriented Action Planning (GOAP) is a AI architecture where an agent is provided with a set of potential actions and a goal (a desired world state). Instead of the developer manually scripting every transition (as in a Finite State Machine or Behavior Tree), a planner dynamically calculates the most efficient sequence of actions to reach that goal based on current world conditions. This allows for emergent behavior, as NPCs can find new ways to solve problems if their initial plan is interrupted.
Designer-Centric Features
A primary focus of this plugin was accessibility for game designers:
- Action & Goal Creation: Designers can easily define new actions and goals directly within the editor.
- Blueprint & C++ Support: To provide maximum flexibility, actions can be fully scripted in Blueprints for rapid prototyping or implemented in C++ for performance-critical logic.
- Smart Object Integration: The plugin is designed to work with Unreal Engine’s Smart Objects , allowing NPCs to interact with the environment dynamically by discovering actions “pinned” to objects in the world.
Technical Implementation
The plugin architecture follows the GOAP model:
- World State: Represented as a lightweight key-value dictionary to track essential variables (e.g.,
AmmoCount,IsHungry,TargetVisible). - Planner Algorithm: Uses an A* algorithm to find the lowest-cost path from the current world state to the desired goal state.
- Plan Recalculation: Plans are dynamically updated if the world state changes significantly, the current plan is completed, or a plan is no longer valid.