Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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.
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.
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.
The AI Brain Graph editor is a tool used to create Corgi/TopDown Engines AI logic through a visual node editor.
The tool is built on top of xNode by Thor Brigsted.
A graph is an asset stored in your project Assets folder. To create one:
Right click anywhere in the Assets folder
Select Create > The Bit Cave > AI Brain Graph
Rename the brain asset
Double click on it to show the editor window
Like the graph, a subgraph is an asset stored in your project Assets folder. To create one:
Right click anywhere in the Assets folder
Select Create > The Bit Cave > AI Brain Graph
Rename the brain asset
Double click on it to show the editor window
To add nodes to the graph (or subgraph) simply right click on any free space and select the desired node.
Please check the Node Reference page for a list of available nodes.
When you add a graph to a Corgi/TopDown character, the system will parse your nodes and will translate them to AIBrain/AIAction/AIDecision components.
To achieve this, all you have to do is to add one of these components:
AI Brain Generator: this component will generate all needed elements to the character
AI Brain Pluggable: similar to the previous component, but the generation will be at runtime
You can install the plugins (for both engines) in two ways:
From the Unity Asset Store: usually the quickest and best solution
From the development repository on GitHub
On the Asset Store you will find the latest stable version:
Install the latest version of Corgi Engine on your project
Install the extension from the Unity Asset Store
Downloading the plugin on GitHub will give you access to the latest (and, sometimes, less stable) features. You will have to follow these steps:
Install the latest version of Corgi Engine on your project
Download the latest release of xNode (freely available on GitHub) and add it to your Unity project
Download the latest develop branch release of AI Brain Extensions for MMTools (freely available on GitHub) and add it to your Unity project
Download the latest develop branch release of AI Brain Extensions for Corgi Engine (freely available on GitHub) and add it to your Unity project
On the Asset Store you will find the latest stable version:
Install the latest version of TopDown Engine on your project
Install the extension from the Unity Asset Store
Downloading the plugin on GitHub will give you access to the latest (and, sometimes, less stable) features. You will have to follow these steps
Install the latest version of TopDown Engine on your project
Download the latest release of xNode (freely available on GitHub) and add it to your Unity project
Download the latest develop branch release of AI Brain Extensions for MMTools (freely available on GitHub) and add it to your Unity project
Download the latest develop branch release of AI Brain Extensions for TopDown Engine (freely available on GitHub) and add it to your Unity project
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
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.
Can Transition To Self: if set to false, self referencing transitions will be removed (for instance Idle > Idle)
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
Transitions (multiple Transition connections): a list of transitions that will let the system exit from this state
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
This node has no attributes.
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
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
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.
Label: corresponds to the regular AIAction label
Depending on the corresponding AIAction, you'll have access to a list of paramenters
This node has no input connections.
Output (multiple Action connections): a single AI Decision Node that will let the AI Brain exit from the actual state
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.
Label: corresponds to the regular AIDecision label
Depending on the corresponding AIDecision, you'll have access to a list of paramenters
This node has no input connections.
Output (multiple Decision connections): a single AIDecision Node that will let the AI Brain exit from the actual state
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.
This node has no input attributes.
This node has no input connections.
This node has no output connections.
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.
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
States In (multiple State connections): a list of entry points from other states transitions
This node has no output connections.
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
This node has no input attributes.
This node has no input connections.
Transitions (multiple Transition connections): a list of transitions that will let the system exit all included states
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)
Subgraph: the subgraph data
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)
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.
This node has no attributes
This node has no input connections.
Input (single State connection): this node will generate a State In connection in the subgraph node of the parent graph
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.
This node has no attributes
Output (single Transition connection): this node will generate a Transition Out connection in the subgraph node of the parent graph
This node has no output connections.
This action will clean up a gameobject from all AIBrain, AIDecision and AIActions components.
Right click a GameObject in the Hierarchy window
Select The Bit Cave > Remove Brain System
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.
Right click on a free spot in the graph/subgraph canvas
Select Enable Node Collapsing/Disable Node Collapsing
In this page you will find listed all the features of the package: all of them are tools for MoreMountains AIBrain system.
The AI Brain Graph system lets you create AIBrains systems by using a node system.
The AIBrain Graph is based on xNode, an opensource project by Thor Brigsted.
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
An AI Pluggable Brain component for runtime generation of AI systems
The AIBrain Debugger 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
Force the brain Target during gameplay
Track current/previous brain state tracking
The Master/Brain 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
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.
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.
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
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 AIActionMoveTowardsTarget3D and an AIActionAIMWeaponATMovement action
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
To create the AI Brain Graph we will need these nodes:
Two states
Two transistions
Three actions
One decision
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
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
Each state should always have a unique name
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.
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
Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding
Connect the Output element to the Decision input of the patrolling state AI Transition node
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 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
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
Connect the Output element to the Actions input of the MoveTowardsTarget state node
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
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.
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
Click the Generate button and you will get the full working TopDown AI system for the PatrolAndMoveAI (try comparing it with the original prefab)
Once you are happy with your brain, you can safely remove the AI Brain Generator component as it is not used during gameplay
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)
Editor Play button and you should see the TopDown Engine AI Brain structure generated
The AI Brain Pluggable is an extension of the regular TopDown Engine AI Brain, so you'll have to keep it in your gameObject
Welcome to the AIBrain Extensions for MoreMountains Unity3D engines (i.e.: Corgi and TopDown) documentation.
This project is maintained by Marco Secchi and it is free and open-source. If you find it useful, please consider supporting it with a one-time donation on Paypal.
The project includes a set of tools that will (hopefully) ease your workflow with the AIBrain system.
The Corgi Engine is a Unity 2D + 2.5D Platformer Kit, available on the Unity Asset Store. If you want to know more about it, please read the official documentation.
Alternatively, for a quick introduction, you can check the following feature video:
The TopDown Engine is a complete solution for top-down games, available on the Unity Asset Store. Official documentation can be found on MoreMountains website.
For a quick feature walkthrough, please check the video below:
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 .
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).
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 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)
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
Add the same channel to the master AIActionChangeAIBrainStateCommand component
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 and check that everything is working.
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.
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
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
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)
To create the AI Brain Graph we will need these nodes:
Two states
Two transistions
Two actions
Two decisions
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
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
Each state should always have a unique name
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
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
Connect the Output element to the Decision input of the patrol state AI Transition node
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
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
Connect the Output element to the Actions input of the Patrol state node
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
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
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.
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
Click the Generate button and you will get the full working Corgi AI system for the RetroSwordsman (try comparing it with the original prefab)
Once you are happy with your brain, you can safely remove the AI Brain Generator component as it is not used during gameplay
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)
Hit the Editor Play button and you should see the Corgi AI Brain structure generated
The AI Brain Pluggable is an extension of the regular Corgi AI Brain, so you'll have to keep it in your gameObject
The AIBrain Debugger tool lets you peek into some inner workings of an AIBrain and modify runtime behaviours.
To check the debugger in function, please watch the video below:
To open the debugger window, simply select from the Main menu Tools > The Bit Cave > AI Brain Debugger.
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.
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
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)
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
Which actions the brain is performing
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
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 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).
Note that you can force the transition even to a disconnected state: this is pretty useful if you are working with the .