Comment on page
Code
- 1.Create a new scene
- 2.Create a new GameObject called
Goap
, add theGoapRunnerBehaviour
to it.

Goap Runner Behaviour
- 3.Create a class called
WanderTarget
that extendsTargetKeyBase
.
WanderTarget.cs
1
using CrashKonijn.Goap.Behaviours;
2
3
public class WanderTarget : TargetKeyBase
4
{
5
}
- 4.Create a class called
IsWandering
that extendsWorldKeyBase
.
IsWandering.cs
1
using CrashKonijn.Goap.Behaviours;
2
3
public class IsWandering : WorldKeyBase
4
{
5
}
- 5.Create a class called
GoapSetConfigFactory
that extendsGoapSetConfigFactoryBase
and override theCreate
method.
GoapSetConfigFactory.cs
1
using CrashKonijn.Goap.Behaviours;
2
using CrashKonijn.Goap.Classes.Builders;
3
using CrashKonijn.Goap.Configs.Interfaces;
4
using CrashKonijn.Goap.Resolver;
5
using CrashKonijn.Goap.Enums;
6
7
public class GoapSetConfigFactory : GoapSetFactoryBase
8
{
9
public override IGoapSetConfig Create()
10
{
11
var builder = new GoapSetBuilder("GettingStartedSet");
12
13
// Goals
14
builder.AddGoal<WanderGoal>()
15
.AddCondition<IsWandering>(Comparison.GreaterThanOrEqual, 1);
16
17
// Actions
18
builder.AddAction<WanderAction>()
19
.SetTarget<WanderTarget>()
20
.AddEffect<IsWandering>(EffectType.Increase)
21
.SetBaseCost(1)
22
.SetInRange(0.3f);
23
24
// Target Sensors
25
builder.AddTargetSensor<WanderTargetSensor>()
26
.SetTarget<WanderTarget>();
27
28
// World Sensors
29
// This example doesn't have any world sensors. Look in the examples for more information on how to use them.
30
31
return builder.Build();
32
}
33
}
- 6.Add the
GoapSetConfigFactory
to theGoap
GameObject. Make sure to add theGoapSetConfigFactory
to theGoapRunnerBehaviour
's factories property.

Goap Runner
- 7.Create a script called
GoapSetBinder
. This script will assign aGoapSet
to theAgent
.
GoapSetBinder.cs
1
using CrashKonijn.Goap.Behaviours;
2
using UnityEngine;
3
4
public class GoapSetBinder : MonoBehaviour {
5
public void Awake() {
6
var runner = FindObjectOfType<GoapRunnerBehaviour>();
7
var agent = GetComponent<AgentBehaviour>();
8
agent.GoapSet = runner.GetGoapSet("GettingStartedSet");
9
}
10
}
- 8.Create a sphere
GameObject
calledAgent
. Add theAgentBehaviour
,AgentMoveBehaviour
,AgentBrain
andGoapSetBinder
to theGameObject
.

Agent
- 9.Run the scene. The agent should move around randomly.
Last modified 2mo ago