In this project I created zombie Nonplayable Characters (NPCs) that use Goal Oriented Action Planning (GOAP) to drive their logic and behaviors. GOAP is basically a design pattern that allows developers to create an NPC system that makes gameplay feel more immersive because the NPCs can make decisions about their actions instead of cycling through a predictable routine.
To keep it brief, and potentially over simplify it, my implementation of GOAP uses 5 parts:
State Data: Each NPC (or Agent) is capable of sensing information in the game world. The important bits of information are stored in simple key value pairs. This includes things like resources, tools, objects in the world. State data is specific to each AI agent.
Agents: NPCs in the game. Each Agent has its own state data, but it doesn’t always know what to do with that information, so they need a little help from the planner.
Goals: Of course these are objectives. Each goal is directly related to a desired value in the state data. For example, state data contains the following key value pair: {player alive: true}. One of the NPCs goals is to eliminate the player so the desired state would be {player alive: false}. Multiple goals can exist at the same time so it’s important to have priority defined for the goals.
Actions: Units of activity that lead to a goal being met. This is things like moving to a location or picking up an item. Each action has 3 parts: a precondition, the action, and an effect. The precondition must be true for the action to be performed. The NPC can’t use an item if it’s not in its inventory, so the precondition must check that the NPC has the item. The action is the actual task. This includes things like moving to a location or picking up an item. The effect defines the change to the state data and impacts the next selected action. If the action was moving to another location, the Agent’s state data should reflect that move as an effect.

Planner: It’s essentially the responsible adult. When an Agent does not know what to do, it reaches out to the planner with its state data. The planner evaluates the state data and determines what the agent’s goal should be. Then it uses Dijkstra’s algorithm to determine the best set of actions that’ll most likely accomplish the goal. The plan is sent back to the Agent to be executed
In addition to these 5 things I also needed a graph (aka adjacency matrix) to represent available paths and a way for NPCs to change their minds when priorities change or plans cannot be completed.
I was able to implement this entire system using Blueprints and State Trees in UE5. I was also able to use an Actor Component to implement the Planner. The result has been zombies that feel much more random than other NPCs I’ve made. Through this project I was able to revisit useful search algorithms and find more interesting uses for State Trees. For more information, check out the full video here.




Leave a comment