The AI Brain Graph comes packed with four main type of nodes:
AI Brain State Node
AI Transition Node
AI Action Node
AI Decision Node
Additionally, you'll get some helper nodes:
Comment Node
AI Brain State Alias Node
AI Brain Any State Node
Finally, when you work with a Subgraph, you have access to:
AI Brain Subgraph Nodes
AI State In Nodes
AI Transition Out Nodes
Main Nodes
AI Brain State Node
A State node represents a single state in the MMTools AIBrain.
Each state should be given a unique name by right-clicking the header and choosing Rename.
The Set as starting state button will set the state as the first one in the MMTools AIBrain states list.
Attributes
Can Transition To Self: if set to false, self referencing transitions will be removed (for instance Idle > Idle)
Inputs
States In (multiple State connections): a list of entry points from other states transitions
Actions (multiple Action connections): a list of actions that should be performed when entering the state itself
Outputs
Transitions (multiple Transition connections): a list of transitions that will let the system exit from this state
AI Transition Node
A Transition node represents a single transition from a state in the MMTools AI Brain: a state can have more than one transition.
If you wish, you can rename the node by right-clicking the header and choosing Rename but this won't affect the AI generation.
A Transition node should always have a connected AIDecision node
Attributes
This node has no attributes.
Inputs
Decision (single Decision connection): a single AI Decision Node that will let the AI Brain exit from the actual state
Input (single Transition connection): a single connection from the AI Brain State
Outputs
True State (single State connection): a connection to the state that should be activated when the decision is true
False State (single State connection): a connection to the state that should be activated when the decision is false
AI Action Node
Action nodes are graph representations of AIAction components. They come with a single output element that should be connected to the state. This will tell the state itself that this action should be executed.
A node may have some parameters, corresponding with the Corgi/TopDown engine AIAction components.
If you wish, you can rename the node by right-clicking the header and choosing Rename but this won't affect the AI generation.
Attributes
Label: corresponds to the regular AIAction label
Depending on the corresponding AIAction, you'll have access to a list of paramenters
Inputs
This node has no input connections.
Outputs
Output (multiple Action connections): a single AI Decision Node that will let the AI Brain exit from the actual state
AI Decision Node
Decision nodes are a graph representation of AIDecision components. They come with a single output element that should be connected to a state transition. This will define the condition to exit the state.
If you wish, you can rename the node by right-clicking the header and choosing Rename but this won't affect the AI generation.
Attributes
Label: corresponds to the regular AIDecision label
Depending on the corresponding AIDecision, you'll have access to a list of paramenters
Inputs
This node has no input connections.
Outputs
Output (multiple Decision connections): a single AIDecision Node that will let the AI Brain exit from the actual state
Helper Nodes
Comment Node
Comment nodes have the only purpose of letting you add notes in your graph. They won't generate anything in the character AI Brain System.
Clicking on the header will let you enter edit note.
Attributes
This node has no input attributes.
Inputs
This node has no input connections.
Outputs
This node has no output connections.
AI Brain State Alias Node
The AI Brain State Alias Node will let you create alias elements for your states: this will avoid main spaghetti like brains when things get complicated.
Attributes
Available States: the node will show a list of nodes:
In the main graph all nodes and subgraph-exposed nodes will be shown
In a subgraph, only inner nodes will be shown
Inputs
States In (multiple State connections): a list of entry points from other states transitions
Outputs
This node has no output connections.
AI Brain Any State Node
The AI Brain Any State node will let you generate Decision/Transition logic for all nodes in your graph:
If added in a main Graph, also subgraph States will be affected
If added in a subgraph, only subgraph States will be affected
Attributes
This node has no input attributes.
Inputs
This node has no input connections.
Outputs
Transitions (multiple Transition connections): a list of transitions that will let the system exit all included states
Subgraph Nodes
AI Brain Subgraph Node
A Subgraph node is a special state node, that lets you create a inner state/decision/action logic.
It can be set as a starting node (in this case its inner starting node will be used).
You can create a subgraph asset and assign it to the Subgraph field.
You cannot create nested subgraphs (i.e.: you cannot add a subgraph inside a subgraph)
Attributes
Subgraph: the subgraph data
Inputs
State In(list of multiple State connections): a dynamically generated list of state connections (see AI State In Nodes)
Outputs
Transition Out (list of single Transition connections): a dynamically generated list of transition connections (see AI Transition Out Nodes)
AI State In Node
The AI State In node exposes an AI Brain State node inside a subgraph to the parent brain graph.
State In nodes are only available in a subgraph.
Attributes
This node has no attributes
Inputs
This node has no input connections.
Outputs
Input (single State connection): this node will generate a State In connection in the subgraph node of the parent graph
AI Transition Out Node
The AI Transition Out node exposes an AI Transition node connection inside a subgraph to the parent brain graph.
Transition Out nodes are only available in a subgraph.
Attributes
This node has no attributes
Inputs
Output (single Transition connection): this node will generate a Transition Out connection in the subgraph node of the parent graph
Outputs
This node has no output connections.
Features
In this page you will find listed all the features of the package: all of them are tools for MoreMountains AIBrain system.
1. AIBrain Graph
The AI Brain Graph system lets you create AIBrains systems by using a node system.
An AIBrain Graph for Corgi Engine
The AIBrain Graph is based on xNode, an opensource project by .
The graph includes the following features;
A visual editing canvas with nodes for all the official AIDecisions and AIActions of Corgi and TopDown Engines
A subgraph system for better reorganization and reusability
An AI Brain Generator component, for quick creation of brain system starting from a brain graph
2. AIBrain Debugger
The system will let you peek into some of the AIBrain inner workings and test states at runtime.
The debugger includes the following features:
An AIBrainDebuggable component, that is an extension of the regular AIBrain component
An AIBrain Debugger window to check what's going on at runtime including:
Force transitions during gameplay
3. Master/Slave Brains
The system will let you control an AIBrain (or a group of AIBrains) from another point in your game, usually from another AIBrain.
The Master/Brain system includes the following features:
A channel system to send brain commands through the MMEventManager
A Master component to send state change commands through a channel
A Slave component to receive state change commands from one or more channels
TopDown Engine - Getting Started Tutorial
In this tutorial you'll learn the basic steps of the AIBrain graph for TopDown Engine.
Note: To get you started using the AI Brain Graph, you should first follow the Install instructions and check that everything is working.
The Tutorial Scene
First of all, look for the MinimalAI3D_Tutorial scene (and open it), that will serve as a starting point for this tutorial. Basically, it is the TopDown MinimalAI3D scene with all enemies removed (with the exception of PatrolAndMoveAI).
Open the AIs group to check the content: you will find the PatrolAndMoveAI prefab along with two other gameObjects (stripped out of all AI components): PatrolAndMoveAI_Generated and PatrolAndMoveAI_Pluggable.
Creating the AI Brain Graph
To start working with the graph, you'll need to create an AI Brain Graph:
In the Project panel, right-click the mouse button and select Create > The Bit Cave > AI Brain Graph
Rename the newly created asset PatrolAndMoveBrain (or anything you deem appropriate)
Double-click on the asset to open the Editor
The PatrolAndMoveAI Brain Structure
Select the PatrolAndMoveAI prefab in scene and look at the AI Brain, AI Actions and AI Decisions components: we want to replicate the same structure with the AI Brain Graph:
The AI Brain has two states: Patrolling and MoveTowardsTarget
While in Patrolling the character will perform an AIActionMovePatrol3D and an AIActionAimWeaponAtMovement action
While in MoveTowardsTarget the character will perform an
To create the AI Brain Graph we will need these nodes:
Two states
Two transistions
Three actions
Creating the States
First of all, let's create the two states:
Right click on the AI Brain graph canvas and choose AI > Brain State: this will create a state
Right click on the node header and choose Rename. Rename the state Patrolling and select Apply
Repeat the first two steps, creating another node called MoveTowardsTarget
Each state should always have a unique name
Adding Transitions
The Patrolling state has a single transition, so we are going to create it:
Right click on the Graph canvas and select AI > Transition: this will add a transition node
Click on the transitions output in Patrolling state and drag it to the Input element of the transition node
There's no decision for the MoveTowardsTarget state, so we won't need a transition.
Adding AI Decisions
The original character has a single decision, connected with the Patrolling state, so let's add it to the graph.
Right click on the graph canvas and select AI > Decision > 3D > Detect Target Radius
Set the Radius to 8
Set the Target Layer Mask to Player
Adding AI Actions
The swordsman has three actions, with one of them in common with both states: let's add them to the graph.
For the Patrolling state:
Right click on the graph canvas and select AI > Action > 3D > Move Patrol
Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding
Connect the Output
For the MoveTowardsTarget state:
Right click on the graph canvas and select AI > Action > 3D > Move Towards Target
Connect the Output element to the Actions input of the MoveTowardsTarget state node
You don't need to create a second Aim Weapon At Movement
Connecting Transitions
The last step to complete the brain graph is to connect the transitions True/False states. In this case we only need the True one:
Connect the True State of the patrolling AI Transition to the States in input of the MoveTowardsTarget state
Generating the Character AIBrain System
We are now ready to add the brain graph to a gameObject and generate all the TopDown Engine AI structure: we have two options for this.
AI Brain Generator
The AI Brain Generator component adds a static brain structure to your character, just like you are used to do in TopDown Engine:
Enable the PatrolAndMoveAI_Generated gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Generator
Drag the PatrolAndMoveBrain we created above in the AI Brain Graph field
Once you are happy with your brain, you can safely remove the AI Brain Generator component as it is not used during gameplay
AI Brain Pluggable
The AI Brain Pluggable generates all Corgi AI system at runtime from a list of brain graphs:
Enable the PatrolAndMoveAI_Pluggable gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Pluggable
Drag the PatrolAndMoveBrain in the AI Brain Graphs field: this is an array of elements, so you can add more than one (one will be chosen randomly at runtime)
The AI Brain Pluggable is an extension of the regular TopDown Engine AI Brain, so you'll have to keep it in your gameObject
Creating Custom Nodes
If you are working on a game made with Corgi Engine, chances are you are going to create new AI Decisions and AI Actions: the AI Brain Graph is completely extensible, so you can create your own nodes.
Basically, each node acts as a component generator for the corresponding action or decision, so you'll just have to pass the correct attributes.
Creating AI Action Nodes
To create your own action nodes, you will have to extend the
AIActionNode
class and override a single method, called
AddActionComponent
: this component returns an instance of the Corgi
AIAction
you want to add with this node.
As an example, please take a look at the AIActionJumpNode that corresponds to the AIActionJump for the Corgi Engine:
Please note the [CreateNodeMenu("AI/Action/Jump")] that adds this node to the graph contextual menu.
Creating AI Decision Nodes
To create your own decision nodes, you will have to extend the AIDecisionNode class and override a single method, called AddDecisionComponent: this component returns an instance of the Corgi (or TopDown Engine) AIDecision you want to add with this node.
As an example, please take a look at the AIDecisionHitNode that corresponds to the AIDecisionHit :
Please note the [CreateNodeMenu("AI/Decision/Hit")] that adds this node to the graph contextual menu.
using MoreMountains.CorgiEngine;
using MoreMountains.Tools;
using UnityEngine;
namespace TheBitCave.CorgiExensions.AI
{
/// <summary>
/// A node representing a Corgi <see cref="MoreMountains.CorgiEngine.AIActionJump"/> action.
/// </summary>
[CreateNodeMenu("AI/Action/Jump")]
public class AIActionJumpNode : AIActionNode
{
public int numberOfJumps = 1;
public override AIAction AddActionComponent(GameObject go)
{
var action = go.AddComponent<AIActionJump>();
action.Label = label;
action.NumberOfJumps = numberOfJumps;
return action;
}
}
}
using UnityEngine;
using MoreMountains.CorgiEngine;
using MoreMountains.Tools;
namespace TheBitCave.CorgiExensions.AI
{
/// <summary>
/// A node representing a Corgi <see cref="MoreMountains.CorgiEngine.AIDecisionHit"/> decision.
/// </summary>
[CreateNodeMenu("AI/Decision/Hit")]
public class AIDecisionHitNode : AIDecisionNode
{
public int numberOfHits = 1;
public override AIDecision AddDecisionComponent(GameObject go)
{
var decision = go.AddComponent<AIDecisionHit>();
decision.Label = label;
decision.NumberOfHits = numberOfHits;
return decision;
}
}
}
An AI Pluggable Brain component for runtime generation of AI systems
The chracters will exit the Patrolling state if the target is within range (AIDecisionDetectTargetRadius3D)
The character will not exit the MoveTowardsTarget state after a while
One decision
On the Patrolling node, click the Set as starting state button: this will set the Patrolling node as the entry state in the character brain
Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding
Connect the Output element to the Decision input of the patrolling state AI Transition node
element to the
Actions
input of the
Patroling
state node
Right click on the graph canvas and select AI > Action > Aim Weapon At Movement
Connect the Output element to the Actions input of the Patrolling state node
Connect the Output element to the Actions input of the MoveTowardsTarget state node
Click the Generate button and you will get the full working TopDown AI system for the PatrolAndMoveAI (try comparing it with the original prefab)
Editor Play button and you should see the TopDown Engine AI Brain structure generated
Editor Resources
Editor Actions
Remove Brain System
This action will clean up a gameobject from all AIBrain, AIDecision and AIActions components.
How to Use
Right click a GameObject in the Hierarchy window
Select The Bit Cave > Remove Brain System
Graph Utilities
Node Collapsing
To make the graph (or subgraph) more readable, you can enable node collapsing for AI Action and AI Decision nodes. When enabled, this feature will show only the Label field and the output connection.
When a node is selected, it will automatically expand to show all available properties.
How to Use
Right click on a free spot in the graph/subgraph canvas
The AIBrain Graph system is based on , an open-source project by : some of the settings can be configured through the Preferences panel (In the Preferences panel, select Node Editor).
In this tutorial you'll learn the basic steps of the AIBrain graph for Corgi Engine.
Note: To get you started using the AI Brain Graph, you should first follow the Install instructions and check that everything is working.
The Tutorial Scene
First of all, look for the AIBrain_Tutorial scene (and open it), that will serve as a starting point for this tutorial. Basically, it is the Corgi RetroAI scene with all enemies removed (with the exception of RetroSwordsman).
Open the Enemies group to check the content: you will find the RetroSwordsman prefab and two other gameObjects (stripped out of all AI components): RetroSwordsmanGenerated and RetroSwordsmanPluggable.
Creating the AI Brain Graph
To start working with the graph, you'll need to create an AI Brain Graph:
In the Project panel, right-click the mouse button and select Create > The Bit Cave > AI Brain Graph
Rename the newly created asset RetroSwordman AIBrain (or anything you deem appropriate)
Double-click on the asset to open the Editor
The RetroSwordsman AI Brain Structure
Select the RetroSwordsman prefab in scene and look at the AI Brain, AI Actions and AI Decisions components: we want to replicate the same structure with the AI Brain Graph:
The AI Brain has two states: Patrol and Shooting
While in Patrol the swordsman will perform an AIActionPatrol action
While in Shooting the swordsman will perform an AIActionShoot action
To create the AI Brain Graph we will need these nodes:
Two states
Two transistions
Two actions
Creating the States
First of all, let's create the two states:
Right click on the AI Brain graph canvas and choose AI > Brain State: this will create a state
Right click on the node header and choose Rename. Rename the state Patrol and select Apply
Repeat the first two steps, creating another node called Shooting
Each state should always have a unique name
Adding Transitions
Each state has a single transition, so we are going to create two and connect them with Patrol and Shooting:
Right click on the Graph canvas and select AI > Transition: this will add a transition node
Click on the transitions output in Patrol state and drag it to the Input element of the transition node
Repeat the first two steps for the Shooting state
Adding AI Decisions
The original swordsman has two decisions, each one connected with a state, so let's add them to the graph.
For the Patrol state:
Right click on the graph canvas and select AI > Decision > Detect Target Radius
Set the Radius to 4
Set the Target Layer to Player
For the Shooting state:
Right click on the graph canvas and select AI > Decision > Time In State
Let the fields to their default values
Connect the Output element to the Decision input of the shooting state AI Transition node
Adding AI Actions
The swordsman has two actions, each one connected with a state: let's add them to the graph.
For the Patrol state:
Right click on the graph canvas and select AI > Action > Patrol
Check the Avoid Falling value
Set the Hole Detection Offset x value to 1
For the Shooting state:
Right click on the graph canvas and select AI > Action > Shoot
Check the Aim At Target value
Connect the Output element to the Actions input of the Shooting state node
Connecting Transitions
The last step to complete the brain graph is to connect the transitions True/False states. In this case we only need the True ones:
Connect the True State of the patrol AI Transition to the States in input of the Shooting state
Connect the True State of the shooting AI Transition to the States in input of the Patrol state
Generating the Character AIBrain System
We are now ready to add the brain graph to a gameObject and generate all the Corgi AI structure: we have two options for this.
AI Brain Generator
The AI Brain Generator component adds a static brain structure to your character, just like you are used to do in Corgi:
Enable the RetroSwordsmanGenerated gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Generator
Drag the RetroSwordsman AIBrain we created above in the AI Brain Graph field
Once you are happy with your brain, you can safely remove the AI Brain Generator component as it is not used during gameplay
AI Brain Pluggable
The AI Brain Pluggable generates all Corgi AI system at runtime from a list of brain graphs:
Enable the RetroSwordsmanPluggable gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Pluggable
Drag the RetroSwordsman AIBrain in the AI Brain Graphs field: this is an array of elements, so you can add more than one (one will be chosen randomly at runtime)
The AI Brain Pluggable is an extension of the regular Corgi AI Brain, so you'll have to keep it in your gameObject
Using Master/Slave AIBrains
The Master/Slave system implements a set of methods to control AIBrains (set as Slaves) from other AIBrains (set as Masters) or other parts of the application through the Corgi/TopDown Event System.
Using the System
The two main actors involved in this system are:
Brain Master: not necessarily connected with a brain, it is used to send State change command events through dedicated channels
Brain Slave: this element listens for State change command events and forces the AIBrain behavior
A Master can also be a Slave and listen to events (even those dispatched by itself).
BrainMaster Ability
The BrainMaster ability component lets you send state change commands to slave brains through a dedicated channel: usually this is achieved through an AIActionChangeAIBrainStateCommand but you can access the SendCommand method:
channel is used to filter who will receive and execute the command
newStateName is the state the AIBrain should transition in
target is the AIBrain target (if any)
This ability doesn't extend the regular Corgi/TopDown abilities, so it doesn't need a Character component: this means you can use anywhere you need (i.e.: with a some trigger or any game logic).
The Brain Slave Ability
The BrainSlave ability component is used to receive state change commands through a dedicated channel.
The slave can listen to one or more channels.
Whenever an event is received, the slave will try to change the AIBrain to the new state.
As an alternative, the state change can be also forced through the TransitionToState() method:
newStateName is the state the AIBrain should transition in
target is the AIBrain target (if any)
Channels
To use the Master/Slave communication system, you will have to create a Channel, that will be added to the slave channel list:
Select Create > The Bit Cave > MasterSlave > State Command Channel
Rename the newly created asset
Add it to your slave Channels list
Tips&Tricks
Creating a Reroute Node
When connecting two nodes, you can create a reroute by right-clicking the mouse button. The reroute node can then be freely moved.
To delete the reroute, right-click on it and select the Remove option.
Add the same channel to the master AIActionChangeAIBrainStateCommand component
The swordsman will exit the Patrol state if the target is within range (AIDecisionDetectTargetRadius)
The swordsman will exit the Shooting state after a while (AIDecisionTimeInState)
Two decisions
On the Patrol node, click the Set as starting state button: this will set the Patrol node as the entry state in the character brain
Connect the Output element to the Decision input of the patrol state AI Transition node
Connect the Output element to the Actions input of the Patrol state node
Click the Generate button and you will get the full working Corgi AI system for the RetroSwordsman (try comparing it with the original prefab)
Hit the Editor Play button and you should see the Corgi AI Brain structure generated
The AIBrain Debugger
The AIBrain Debugger tool lets you peek into some inner workings of an AIBrain and modify runtime behaviours.
The AIBrain Debugger window
To check the debugger in function, please watch the video below:
Opening the AIBrain Debugger Window
To open the debugger window, simply select from the Main menu Tools > The Bit Cave > AI Brain Debugger.
Using the AIBrainDebuggable Component
To debug a brain, you will need an AIBrainDebuggable component, that is an extension of the regular MMTools AIBrain.To add such brain select Add Component > CorgiExtensions > AI > AI Brain Debuggable.
This brain works exactly like a regular brain, so you can add states and transitions, but it will give some more additional info to the debugger.
Debugging an AIBrain
To start debugging a debuggable AI Brain, all you have to do is to play the scene from the Unity Editor and select a gameobject with an AIBrainDebuggable. The brain is divided in three main sections:
Brain state
Transitions
Target
Brain State
The Brain State section shows the brain status during gameplay. Info displayed are:
The selected gameobject
Brain status (active or not)
Current brain target (if any)
Transitions
This section will display all available states in the brain. Each state is displayed as a button, so you can force the transition if it is needed. A state can be:
[C] The current state: in this case the button will be disabled
[>>] A state connected with the current state
A state disconnected with the current state
Note that you can force the transition even to a disconnected state: this is pretty useful if you are working with the .
Target
This section will allow you to set the brain target or remove it if needed.
Note that you can force any kind of target, not just the one selected by the brain.
The previous state and how much time the brain has been in it
The current state and how much time has passed since the brain entered it