@@ -251,7 +251,42 @@ Does not change `TaskStatus.Continue`.
251251
252252## Creating Reusable Behavior Trees
253253
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+ ```
255290
256291## Creating Custom Reusable Nodes
257292
@@ -554,7 +589,7 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
554589 public TreeBuilderCustom (GameObject owner ) : base (owner ) {
555590 }
556591
557- public TreeBuilderCustom (string name = " My Custom Decorator" ) {
592+ public TreeBuilderCustom CustomDecorator (string name = " My Custom Decorator" ) {
558593 return ParentTask <CustomDecorator >(name );
559594
560595 // Or you can code this manually if you need more specifics
0 commit comments