SetNet.BehaviorTree
1.2.0
dotnet add package SetNet.BehaviorTree --version 1.2.0
NuGet\Install-Package SetNet.BehaviorTree -Version 1.2.0
<PackageReference Include="SetNet.BehaviorTree" Version="1.2.0" />
<PackageVersion Include="SetNet.BehaviorTree" Version="1.2.0" />
<PackageReference Include="SetNet.BehaviorTree" />
paket add SetNet.BehaviorTree --version 1.2.0
#r "nuget: SetNet.BehaviorTree, 1.2.0"
#:package SetNet.BehaviorTree@1.2.0
#addin nuget:?package=SetNet.BehaviorTree&version=1.2.0
#tool nuget:?package=SetNet.BehaviorTree&version=1.2.0
SetNet.BehaviorTree
A small generic behavior tree for SetNet AI.
Assemble a tree from Sequence / Selector / Parallel composites, Inverter / Succeeder / Repeat / Cooldown
decorators, and Do / Condition / Wait leaves with a fluent builder, then Tick(ctx, dtMs) it each frame over your
own context type. Nodes return BtStatus.Success / Failure / Running, and Running leaves are resumed on the next
tick. Engine-agnostic and free of any wire protocol — wrap one in an IMobBrain for mob AI, or use it anywhere.
// A goblin: attack if in range, else chase the target, else idle.
var tree = BehaviorTree<Mob>.Build()
.Selector()
.Sequence()
.Condition(m => m.HasTarget && m.InAttackRange)
.Cooldown(1500) // don't swing more than once per 1.5s
.Do(m => m.Attack(m.Target))
.End()
.End()
.Sequence()
.Condition(m => m.HasTarget)
.Do((m, dt) => m.MoveToward(m.Target) ? BtStatus.Running : BtStatus.Success)
.End()
.Do(m => m.Idle()) // fallback leaf
.End()
.Create();
// each server tick:
var status = tree.Tick(mob, dtMs);
Concepts
- Composites open with
Sequence()/Selector()/Parallel()and close withEnd(). Sequence is AND (fails on the first failure), Selector is OR (succeeds on the first success), Parallel ticks every child each frame. - Decorators wrap exactly one node:
Inverter()swaps Success/Failure,Succeeder()forces Success,Repeat(count)loops a child (count ≤ 0= forever),Cooldown(ms)blocks re-running a child until the timer elapses. - Leaves:
Do(Func<TContext, float, BtStatus>)for a full action,Do(Action<TContext>)for a fire-and-succeed side effect,Condition(pred)for a boolean Success/Failure gate,Wait(ms)to stay Running for a duration.Node(...)attaches an already-builtBtNode<TContext>. - Ticking:
Tick(ctx, dtMs)runs one pass and returns aBtStatus;Reset()clears every node's in-progress state. Sequence/Selector remember the child that wasRunningand resume there next tick.
Notes
- Pure library, no wire protocol. The tree runs wherever you tick it — typically server-side inside an
IMobBrain, but it has no networking dependency beyond referencingSetNet. - Actions and conditions are your delegates over
TContext, so one built tree can drive many entities, each with its own context instance. - Prefer a simpler shape? Reach for
SetNet.StateMachinewhen a handful of states and transitions is enough.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- SetNet (>= 1.2.0)
- SetNet.Ticks (>= 1.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.0 | 88 | 8/5/2026 |