AkiGOAP
Modular and high-performed Unity Goal Oriented Action Planner with well designed visual graph editor
Install / Use
/learn @AkiKurisu/AkiGOAPREADME
AkiGOAP
Read this document in Chinese: 中文文档
AkiGOAP is a Goal Oriented Action Planner unity plugin that supports visualization, modular editing, and multi-threading, which integrates the functions of multiple open source GOAP plugins.
Features
-
Two algorithms are implemented
-
Can be accelerated using Job System
-
Visual Graph Editor
- Allow debug in runtime play mode
- Log detail with customized level
- Take snapShot of current plan searching
Supported version
- Unity 2021.3 or Later
Set Up
- Using git URL to download package by Unity PackageManager
https://github.com/AkiKurisu/AkiGOAP.git
How to debug
- Right-click Goal and set Always Banned
- Right-click Goal and set it to the highest priority (only affects a single Goal)
- Right-click Action settings to always meet preconditions (Preconditions)
How To Use
Recommended to play the Samples/Example scene first
- In the Asset folder, right-click the menu
Create/AkiGOAP/GOAPSetto create a GOAPSet - Click
Open GOAP Editorto open the editor - Right-click to create a Goal node or Action node, and drag the two nodes into
GOAP Goal StackandAction Stackrespectively - Create a GameObject to mount GOAPPlanner, and also mount GOAPWorldState
- Write the Agent script, the example is as follows:
using UnityEngine; using UnityEngine.AI; using System.Linq; namespace Kurisu.GOAP.Example { public class ExampleAgent : MonoBehaviour { private IPlanner planner; private NavMeshAgent navMeshAgent; public NavMeshAgent NavMeshAgent=>navMeshAgent; [SerializeField] private GOAPSet dataSet; [SerializeField] internal Transform player; public Transform Player=>player; private void Start() { navMeshAgent=GetComponent<NavMeshAgent>(); planner=GetComponent<IPlanner>(); //You can pass inheritance and use Linq's Cast or OfType to get custom subclasses and perform dependency injection var goals=dataSet.GetGoals(); foreach(var goal in goals.OfType<ExampleGoal>()) { goal.Inject(this); } var actions=dataSet.GetActions(); foreach(var action in actions.OfType<ExampleAction>()) { action.Inject(this); } //Finally you need to inject Goal and Action into Planner planner.InjectGoals(goals); planner.InjectActions(actions); } } } - Mount the Agent script on the GameObject above, and drag in the previously created GOAPSet
- Click Play, and all Goals and Actions will obtain their dependencies for initialization at Start
- Click
Open GOAP Editorof GOAPPlanner to open the editor to view the Priority of all current Goals and the Cost of all Actions - Click
Snapshotin the upper right corner to open the snapshot to view the current Plan (i.e., a sequence of Actions to reach the current Goal)
Backend Explanation
There are differences in the implementation of the two algorithms
-
Main Backend, all run on the main thread, suitable for all types of tasks, Position can be added to Cost calculation, algorithm optimization and improvement from https://github.com/toastisme/OpenGOAP
-
JobSystem Backend, the algorithm uses https://github.com/crashkonijn/GOAP. The created Job can also add Position to Cost calculation, but there are certain restrictions on applicable tasks. For details, see JobSystemBackend Limitations
using UnityEngine;
namespace Kurisu.GOAP.Example
{
public class GoToHome : ExampleAction
{
protected override void SetupDerived()
{
//Register Transform bound to this node
worldState.RegisterNodeTarget(this,agent.Home);
}
}
}
How to optimize performance
Adjust TickType
Since GOAP is relatively expensive to use, we can consider turning off Plan search when it is not needed.
Check ManualUpdateGoal to change Goal updates to manual calls. If ManualActivatePlanner is checked, the Planner will no longer automatically search for Plan and needs to be manually activated by calling ManualActivate(), and the Planner will close again when it loses the Plan for the first time after activation. This option is suitable for some turn-based games. Usually the AI of these games only needs to search for plans in a specific round or a specific time period.
Adjust SearchMode
For example: Target A needs an item, and to obtain the item, you need to first perform <b>Move Action B</b> and then perform <b>Collect Action C</b>. After the Planner searches that the current Action is B, the AI will perform Action B.
If we want the AI to collect behavior C after B is completed, we should notify the Planner to search again after B is completed or search every frame.
The default SearchMode of the Planner in AkiGOAP is Always, which means it will search every frame. If the searched Plan does not match the current Plan, it will be replaced. You can adjust Planner's search timing by modifying SearchMode. If you use OnActionComplete, Planner will search again after Action completes or fails. If you use OnPlanComplete, Planner will search again after Plan completes or fails. Otherwise, it will It will be executed sequentially according to the current Plan after the Action completes or fails.
-
Performance comparison example of Example scene (taking
JobSystemBackendas an example)SearchModeusesAlways<img src="Images/Optimize0.png" />
<img src="Images/Optimize1.png" />SearchModeusesOnActionCompleteorOnPlanComplete
JobSystemBackend Limitations
Assume a scenario
Goal is to make an apple pie (HasApplePie:√)
The Conditions and Effects of available Actions are as follows:
-
Walk to the apple tree and pick apples
<b>Effects:</b> HasApple:√
-
Go to the kitchen
<b>Effects:</b> InKitchen:√
-
Make apple pie
<b>Conditions:</b> InKitchen:√ , HasApple:√
<b>Effects:</b> HasApplePie:√
The current status is
- HasApple:×, HasApplePie:×, InKitchen:×
The theoretical plan is: walk to the [Walk to the apple tree and pick apples] => [Go to the kitchen] => [Make apple pie]
However, the Plan given by the algorithm of JobSystemBackend is [Go to the kitchen] => [Make apple pie], which obviously cannot satisfy the Goal.
Why is there this problem
The algorithm of JobSystemBackend stores whether all Actions can be entered (IsExecutable) in advance before path search, and does not consider the impact caused by the superposition of Conditions during path search, such as the Conditions in path "[Go to the kitchen] => [Make apple pie]" are actually "InKitchen:√ , HasApple:√" instead of the Conditions of [Go to the kitchen], so the wrong path was found.
How to fix
Use MainBackend or add Conditions. For example, change the Conditions of [Go to the kitchen] to "HasApple:√"
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
ui-ux-designer
Use this agent when you need to design, implement, or improve user interface components and user experience flows. Examples include: creating new pages or components, improving existing UI layouts, implementing responsive designs, optimizing user interactions, building forms or dashboards, analyzing existing UI through browser snapshots, or when you need to ensure UI components follow design system standards and shadcn/ui best practices.\n\n<example>\nContext: User needs to create a new dashboard page for team management.\nuser: "I need to create a team management dashboard where users can view team members, invite new members, and manage roles"\nassistant: "I'll use the ui-ux-designer agent to design and implement this dashboard with proper UX considerations, using shadcn/ui components and our design system tokens."\n</example>\n\n<example>\nContext: User wants to improve the user experience of an existing form.\nuser: "The signup form feels clunky and users are dropping off. Can you improve it?"\nassistant: "Let me use the ui-ux-designer agent to analyze the current form UX and implement improvements using our design system and shadcn/ui components."\n</example>\n\n<example>\nContext: User wants to evaluate and improve existing UI.\nuser: "Can you take a look at our pricing page and see how we can make it more appealing and user-friendly?"\nassistant: "I'll use the ui-ux-designer agent to take a snapshot of the current pricing page, analyze the UX against Notion-inspired design principles, and implement improvements using our design tokens."\n</example>
