Nodes

The AI system comes with many built in nodes ready for creating AI. The following gives you a general understanding of the node’s purpose. For more information on the node, hit the show information icon in the inspector.

Action

Add Item

Add the specified item to this inventory.

Contains Item

Does the following inventory contain this item?

Use Item

Use and remove the item from the inventory.

Cannon Enter

Enter a cannon.

Cannon Exit

Exit a cannon.

Follow Graph Points

Navigate to points with the specified speed. Target must be TargetPoints.

Follow Platform Walls

The AI will walk around platforms or walls, cutting corners. A probability of 1 will ensure it always moves to the next corner or it might change direction.

Follow Target

The AI will follow the specified target.

Guard Territory

The AI will follow the target if the target is inside the territory.Else, the AI will move to the guard point. This returns Success when the target is within the stop distance;

Ignore Block Units

The AI will ignore or block other AI units along the pathfinding path.

Pathfinder

The AI will follow a path generated by the pathfinding algorithm. This works with gravity, making it ideal for platformers.

Pathfinder Basic

The AI will follow a path generated by the pathfinding basic algorithm. This ignores the effect of gravity.

Jump

Make the AI Jump.

Jump To

The AI will jump towards the specified target.

Jump In Object

The player can jump into this object to hide from AI.

Jump Out Object

The player will jump out this object on button press.

Push Back

If damaged, the AI will be pushed back (and flash).

Monitor Variable

Check if a blackboard variable has changed value. Typically used for float variables.

Monitor World Variable

Check if a world variable has changed value. This will also work with Health.

Apply Character Velocity

Apply a character’s velocity to this AI.

Apply Gravity

This will simulate gravity. Mostly needed by moving platforms.

Control Player

Control the player in the x-direction by moving it to a point. This will also block player input.

Control Player Transform

Move the player’s transform along a set of points. These points are local to the AI.

Idle

Sometimes it’s useful to have an action where the AI just waits idly.

Indefinite Walk

If the AI hits a wall or air gap, it will change walking direction.

Lets Wiggle

Execute a Lets Wiggle tween. If this AI is a moving platform, then only its position should be modified.

Melee Attack

Perform a melee attack.

Move

This will move the AI with the specified velocity.

Nullify Gravity

Stop the effect of gravity on the AI.

Rotate Around

Rotate the transform around the specified target.

Rotate Position

Rotate the transform’s position around the center point at the specified radius.

Scene Door Enter

After entering a scene, the player will be placed at the door’s position.

Scene Door Exit

If the player enters the door area, the specified scene will load by calling the manage scenes component.

Set Transform

Set the position, rotation, or scale of a transform instantly or by lerping.

Shake

This will shake the AI. Only shake an object if it’s standing still.

Water Float

The AI will float on the waterline.

Find Collider

Find a target collider on the specified layer.

Face Target

The AI will point towards the specified target in the x-axis.

Get Nearest Target

Get the nearest target to the AI from a list and set the reference to this target.

Get Random Target

Get a random target from a list and set the reference to this target.

Nearest 2D Results

Get the nearest target to the AI from a list of physics results and set the reference to this target.

Target Changed

This will return success when the target’s position has changed by the specified distance.

Add To List

Add the specified item to a list.

Animation Signal

Sets an animation signal true for the AI.

BoxCollider2D Size

Change the size and offset of a BoxCollider2D.

Branch On Object Tag

This will read an object’s tag and jump to the specified state. Create as many options as necessary.

Captured By Yoshi

This AI can be captured by Yoshi.

Character Animation Signal

Set the following animation signal true for the specified character.

Chain

A chain created from gameobjects.

Clock

Wait the specified time.

Enable Behaviour

This will enable or disable the specified behaviour or renderer.

Enable Tree

Pause or remove the BehaviorTree from executing. Also specify the active state of the gameobject that belongs to the BehaviorTree.

Flip Children Objects

Flip the children objects of this AI in the x direction of the AI. This will flip the x scale. Run this inside an Always state.

Go To Next State

Jump to another state. Useful if a node you are working with can’t jump to a state.

IncDec Float

Increase or decrease a float variable by the specified amount.

Kill AI

Disable the AI’s Collider and Sprite Renderer.

On Event

Invoke and event.

PauseCollisions

Pause world collisions. If enabled, choose to move transform with Translate or not.

Player Death

Play a death animation for the specified time. This will block player input and disable its collider.

Random Loot

Add a random item from the list to an inventory.

Remove From List

Remove the specified item from a list.

Repeat

This will run the amount of times specified in the repeat value and then return Success.

Reset

This will reset the AI’s position and health. If WorldBool or TransformTracker exists and is true, the AI will be considered dead and deactivated. If so, this will return Success

Set As Child

Set the specified transform as child of the AI or remove it as a child of the AI.

Set Direction

Set the direction of a character.

Set Value

Set the value of the blackboard data.

Set Value From blackboard

Set the value of the blackboard data with that of another blackboard variable.

Set World Float At Rate

Increase or decrease a World Float value at the specified rate.

Skip A Frame

This will wait one frame and then return Success.

Spawn GameObject

Spawn a gameObject at the specified position.

Spawn Point

Reset the AI to the position it had at the beginning of the scene.

Sprite Color

This will modify a sprite’s color by lerping to a new one.

Wait For Player Input

Wait for the player to enter the territory and then for the button to be pressed.

World Effect

Call a world effect at the AI’s position.

Damage Effect

Slow down the enemy, apply damage, and play the specified animation signal for the duration amount.

Damage Flash

Show damage flash.

Composite

Parallel

Runs all child nodes at the same time. This will return Running as long as one of them is running. Once all child nodes complete, it will return Success if one child succeeded, else failure.

Parallel Success

Runs all child nodes at the same time until one of them returns Success. Returns Failure if all them fail.

Parallel Success All

Runs all child nodes at the same time until they all return Success. Will return failure if not all of them succeeded.

Random Selector

This will run one random child node.

Random Sequence

This will shuffle the list of nodes so that the execution order is always randomized.

Selector

This will run every node in the list until one returns Success.

Sequence

This will run every node in the list until one returns Failure.

Decorator

Delay

Run the child node after a time delay.

Inverter

This will invert the output logic of the child node (except for Running). Interrupt logic will work with this decorator.

Repeater

This will execute the child node by the amount of times specified in the repeat value.

Running

This will always return Running.

Timer

This will run a child node for the specified time.

Until Fail

This will run the child node until it returns Failure.

Until Success

This will run the child node until it returns Success.

Conditional

Find Target

Find the specified Target in relation to the AI or Territory.

List Logic

This will compare the size of the specified list to a value.

Variable Logic

This will compare a float variable to a float value.

World Float Logic

Compare a world float to a float value.

CircleCast

Implement a CircleCast using Physics2D. The results can be accessed by Nearest2DResults.

LineCast

Implement a LineCast using Physics2D. The results can be accessed by Nearest2DResults.

OverlapBox

Implement an OverlapBox using Physics2D. The results can be accessed by Nearest2DResults.

OverlapCircle

Implement an OverlapCircle using Physics2D. The results can be accessed by Nearest2DResults.

OverlapCollider

Implement an OverlapCollider using Physics2D. The results can be accessed by Nearest2DResults.

OverlapPoint

Implement an OverlapPoint using Physics2D. The results can be accessed by Nearest2DResults.

RayCast

Implement a RayCast using Physics2D. The results can be accessed by Nearest2DResults.

Layer Result

Rays casted using Single Hit can compare if the resulting object belongs to the specified layer.

Touching Layers

Check if the specified collider is touching any other collider in the specified layer.

Collision Status

Check what a character/AI is interacting with.

Return Failure

This will always return Failure.

InputButtonSO Get

Returns success if InputButtonSO is true.

Input Get

Get Input KeyDown or MouseDown.

Is Quest Active

Is this quest active?

Is Quest Complete

Is this quest complete?

Positional

Check the AI’s position in relation to a target.

Field Of View

Returns Success if the specified target is inside the field of view.

Has Passengers

Does this moving platform have passengers?


Create Nodes

The most common nodes to create will be Conditional and Action nodes. Once the script is created, place it inside the AI/BehaviorTree/Nodes folder and it will become available for use in the AI system. Follow the template below to code your own functionality. The first example is of the Move Action node, which simply adds velocity to the AI.

 using UnityEngine;

 namespace TwoBitMachines.FlareEngine.AI// Include this namespace
 {
    public class Move : Action // Specify the type of node - Action/Conditional/Composite/Decorator
    {
            [SerializeField] public Vector2 velocity;

            // Use this method to implement the behavior
            public override NodeState RunNodeLogic (Root root)
            {
                    if (nodeSetup == NodeSetup.NeedToInitialize)
                    {
                    //       Any member fields that need to be reset/initialized go here.
                    }

                    root.velocity += velocity;// Root is basically the AI
                    return NodeState.Running; // Return Running
                                              // If the behavior completes, return Success or Failure.
            }

            // Use this to reset important variables
            public override void OnReset ( )
            {

            }

// Root contains a few variables to be aware of

// root.velocity  -- the velocity of the AI, read and write to it
// root.direction -- the direction of the AI on the x-axis, read and write to it
// root.position  -- the position of the AI in the game world, read only

// root.hasJumped -- set true if you have added a jumping force to the AI's root.velocity.y
// root.onSurface -- set true if you are creating a hard surface for the AI to stand on

// root.signals.Set ("relevantSignalName") -- set an animation signal if necessary
// root.world     -- reference to WorldCollision, read settings like onGround, onMovingPlatform, etc.
// root.gravity   -- reference to Gravity, if jumping use root.gravity.SetJump (velocity.y);
//                   see the Jump node for more information
// root.movingPlatform   -- reference to MovingPlatform if the AI is of this type, use it to read
//                          hasPassengers or passengerCount
    }

  }
using UnityEngine;

namespace TwoBitMachines.FlareEngine.AI
{
     // This is a Conditional node. This will simply check if the AI is on the ground.
     // This class doesn't actually exist, but it can be created using this code
     // to get this functionality.
     public class AIOnGround : Conditional
     {
             public override NodeState RunNodeLogic (Root root)
             {
                     return root.world.onGround ? NodeState.Success : NodeState.Failure;
             }
     }
 }
using UnityEngine;

namespace TwoBitMachines.FlareEngine.AI
{
    // This is a Decorator, and it will run its child node until it fails.
    public class UntilFail : Decorator
    {
           public override NodeState RunNodeLogic (Root root)
           {
                  NodeState nodeState = children[0].RunChild (root);
                  return nodeState == NodeState.Failure ? NodeState.Success : NodeState.Running;
           }
    }
}