Code
Create a new scene
Create a new GameObject called
Goap
, add theGoapRunnerBehaviour
to it.

Create a class called
WanderTarget
that extendsTargetKeyBase
.
using CrashKonijn.Goap.Behaviours;
public class WanderTarget : TargetKeyBase
{
}
Create a class called
IsWandering
that extendsWorldKeyBase
.
using CrashKonijn.Goap.Behaviours;
public class IsWandering : WorldKeyBase
{
}
Create a class called
GoapSetConfigFactory
that extendsGoapSetConfigFactoryBase
and override theCreate
method.
using CrashKonijn.Goap.Behaviours;
using CrashKonijn.Goap.Classes.Builders;
using CrashKonijn.Goap.Configs.Interfaces;
using CrashKonijn.Goap.Resolver;
using CrashKonijn.Goap.Enums;
public class GoapSetConfigFactory : GoapSetFactoryBase
{
public override IGoapSetConfig Create()
{
var builder = new GoapSetBuilder("GettingStartedSet");
// Goals
builder.AddGoal<WanderGoal>()
.AddCondition<IsWandering>(Comparison.GreaterThanOrEqual, 1);
// Actions
builder.AddAction<WanderAction>()
.SetTarget<WanderTarget>()
.AddEffect<IsWandering>(EffectType.Increase)
.SetBaseCost(1)
.SetInRange(0.3f);
// Target Sensors
builder.AddTargetSensor<WanderTargetSensor>()
.SetTarget<WanderTarget>();
// World Sensors
// This example doesn't have any world sensors. Look in the examples for more information on how to use them.
return builder.Build();
}
}
Add the
GoapSetConfigFactory
to theGoap
GameObject. Make sure to add theGoapSetConfigFactory
to theGoapRunnerBehaviour
's factories property.

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

Run the scene. The agent should move around randomly.
Last updated