SetNet.BehaviorTree 1.2.0

dotnet add package SetNet.BehaviorTree --version 1.2.0
                    
NuGet\Install-Package SetNet.BehaviorTree -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SetNet.BehaviorTree" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.BehaviorTree" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.BehaviorTree" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SetNet.BehaviorTree --version 1.2.0
                    
#r "nuget: SetNet.BehaviorTree, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SetNet.BehaviorTree@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SetNet.BehaviorTree&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.BehaviorTree&version=1.2.0
                    
Install as a Cake Tool

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 with End(). 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-built BtNode<TContext>.
  • Ticking: Tick(ctx, dtMs) runs one pass and returns a BtStatus; Reset() clears every node's in-progress state. Sequence/Selector remember the child that was Running and 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 referencing SetNet.
  • 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.StateMachine when a handful of states and transitions is enough.

License

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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