@@ -251,7 +251,42 @@ Does not change `TaskStatus.Continue`.
251
251
252
252
## Creating Reusable Behavior Trees
253
253
254
- @TODO Document splicing with an example
254
+ Trees can be combined with just a few line of code. This can allow you to create injectable template that bundles different
255
+ nodes for complex functionality such as searching or attacking.
256
+
257
+ Be warned that spliced trees require a newly built tree for injection, as nodes are not deep copied on splice.
258
+
259
+ ``` C#
260
+ using Adnc .FluidBT .Trees ;
261
+ using UnityEngine ;
262
+
263
+ public class MyCustomAi : MonoBehaviour {
264
+ private BehaviorTree _tree ;
265
+
266
+ private void Awake () {
267
+ var injectTree = new BehaviorTreeBuilder (gameObject )
268
+ .Sequence ()
269
+ .Do (" Custom Action" , () => {
270
+ return TaskStatus .Success ;
271
+ })
272
+ .End ();
273
+
274
+ _tree = new BehaviorTreeBuilder (gameObject )
275
+ .Sequence ()
276
+ .Splice (injectTree .Build ())
277
+ .Do (" Custom Action" , () => {
278
+ return TaskStatus .Success ;
279
+ })
280
+ .End ()
281
+ .Build ();
282
+ }
283
+
284
+ private void Update () {
285
+ // Update our tree every frame
286
+ _tree .Tick ();
287
+ }
288
+ }
289
+ ```
255
290
256
291
## Creating Custom Reusable Nodes
257
292
@@ -554,7 +589,7 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
554
589
public TreeBuilderCustom (GameObject owner ) : base (owner ) {
555
590
}
556
591
557
- public TreeBuilderCustom (string name = " My Custom Decorator" ) {
592
+ public TreeBuilderCustom CustomDecorator (string name = " My Custom Decorator" ) {
558
593
return ParentTask <CustomDecorator >(name );
559
594
560
595
// Or you can code this manually if you need more specifics
0 commit comments