13. Make a Decorator

Decorators, also known as conditionals in other Behavior Tree systems, are attached to either a Composite or a Task node and define whether or not a branch in the tree, or a single node, can be executed.

This Decorator is going to stop execution of the Rapid Move To branch of the Behavior Tree once the AI's Pawn is close enough to its target. While this could be handled in the Rapid Move To Task or by just using a Move To Task, this decorator can take in any Actor and can block execution of any branch. This makes it reusable in a number of situations.

Steps

  1. Open the FollowerBT Behavior Tree by Double-clicking it in the Content Browser.

  2. Click New Decorator button.

    It will create in the same folder as the Behavior Tree.

  3. Rename it in the Content Browser to "CloseEnough".

  4. The editor should have already opened it for editing, but if not, Double-click it in the Content Browser.

  5. In the Functions section of the My Blueprint Tab, "Override" PerformConditionCheck.

    override_button.png

  6. Create the following graph in that new function:

    Copy Example

    Click the image to expand it, or click here to open it in the window.

    variables.png

    The variable names, types, and values for this Blueprint:

    Variable Name Type Value
    AI_CON_Ref Follower_AI_CON_C None
    AcceptableDistance Float 0.0 - However, this variable has its "Editable" flag set to True so you can change it, per instance, on the Behavior Tree.
    TargetToFollow BlackboardKeySelector None - However, this variable has its "Editable" flag set to True so you can change it, per instance, on the Behavior Tree.

    As this is a Function Graph, if you use the Code Snippet from the graph image above, you will only get the center portion of the graph, and the beginning and end nodes will not be connected. Just wire those connects as the image shows, and it will work just fine.

  1. Event Receive Condition Check is the event sent to this Blueprint when the Behavior Tree hits a node with this condition on it.

  2. Once again, store the AI Controller so we can reference it later easily.

  3. Get the Actor we want to follow (the Player Pawn).

  4. Get the distance between that Actor and the AI Pawn.

  5. If distance is greater than a configurable amount, then the condition returns True. If not, then it returns False and blocks execution of the portion of the Behavior tree it is on.

This will make it so the Behavior Tree is not constantly cycling to the RapidMoveTo and back out again. Basically, if he caught up to the player, then stop.