ReGoap is a generic C# GOAP (Goal Oriented Action Planning) library with Unity and Godot adapters.
It gives you a planner that chooses a goal, builds a valid action sequence to satisfy it, and lets your runtime execute that sequence while reacting to world changes.
GOAP is a decision-making technique for agents (NPCs, workers, enemies, simulation entities) where behavior is generated from world facts instead of hardcoded behavior trees or giant switch statements.
In GOAP, you define:
- World state facts (example:
hasOre = true,chestSwordCount = 3) - Actions with preconditions and effects (example:
SmeltIngotneeds ore and produces ingot) - Goals as desired world states (example:
chestSwordCount >= 10)
At runtime, the planner searches for a valid chain of actions that transforms the current world state into the goal state.
Why this is useful:
- You add/modify actions and goals without rewriting all transitions.
- Agents can recover from changed world conditions via replanning.
- The system naturally supports emergent sequences from reusable actions.
ReGoap provides:
- A reusable, engine-agnostic planner core (
ReGoap/Core,ReGoap/Planner,ReGoap/Utilities) - Runtime abstractions for agent, action, goal, memory, and sensors
- Engine adapters (Unity and Godot) so you can plug into scene/component workflows
- Debugging support (notably in Godot runtime debugger)
At a high level, each planning cycle is:
- Agent gathers possible goals.
- Planner picks a goal (deterministic or weighted-random mode).
- Planner runs A* search to build a valid action plan.
- Agent executes actions in order.
- On success/failure/world change, agent can re-evaluate and replan.
A key/value fact container describing world conditions.
Examples:
enemyVisible = trueweaponEquipped = falsechestOreCount = 2
A behavior unit with:
- Preconditions: what must be true to run it
- Effects: what it contributes toward goals
- Cost: planning cost used by search
- Runtime
Runlogic: your actual gameplay/sim code
A desired target state plus priority.
The planner chooses among possible goals and attempts to build a valid plan for one.
The agent's current world knowledge.
This is the source-of-truth state the planner reads when generating plans.
A memory updater that writes observed world facts into memory (resource counts, visibility, occupancy, etc).
ReGoap supports comparator-based state matching through ReGoapCondition:
ReGoapCondition.Equal(value)ReGoapCondition.NotEqual(value)ReGoapCondition.GreaterOrEqual(value)ReGoapCondition.LessOrEqual(value)
This is useful for count-based logic such as inventories, chest resources, cooldown thresholds, and score targets.
Plain values still use exact equality matching for backward compatibility.
Goal selection can be deterministic (highest priority first) or weighted-random (priority-biased random).
Settings in ReGoapPlannerSettings:
UseWeightedRandomGoalSelection(defaultfalse)WeightedRandomGoalPriorityPower(default1f)WeightedRandomMinimumWeight(default0.001f)WeightedRandomUseDeterministicSeed(defaultfalse)WeightedRandomSeed(default0)
Deterministic seed mode is helpful for reproducible tests/replays.
ReGoap/Core: interfaces, states, action/goal contractsReGoap/Planner: planner, nodes, settingsReGoap/Utilities: logging and utility helpersReGoap/Unity: Unity adapter + Unity examples/docsReGoap/Godot: Godot adapter + Godot FSMExample/docs
- Unity guide:
ReGoap/Unity/README.md - Godot guide:
ReGoap/Godot/README.md
- Define your world facts in memory/sensors.
- Implement actions with realistic preconditions/effects/costs.
- Implement goals with priorities.
- Attach agent + planner manager.
- Validate behavior in debugger and with tests.
- Tune costs/priorities to shape behavior.
PRs are welcome. Run relevant build/tests for changed engine/runtime areas before submitting.