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:

SendCommand(StateCommandChannel channel, string newStateName, Transform target = null)
  • 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:

TransitionToState(string newStateName, Transform target = null)
  • 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:

  1. Select Create > The Bit Cave > MasterSlave > State Command Channel

  2. Rename the newly created asset

  3. Add it to your slave Channels list

  4. Add the same channel to the master AIActionChangeAIBrainStateCommand component

Last updated