Entity Group

An Entity Group is a collection of AI entities that can share blackboards and be managed together under a common group. These groups facilitate the organization and synchronization of multiple entities, allowing them to share information and make coordinated decisions.

Public Interface

Group Name [get/set]

The name assigned to the group which helps in identifying the group among others.

Entity Entries [get/set]

List of entities added to the group along with their relative execution priorities.

Group Blackboards [get/set]

Group-specific shared blackboards that entities within the group can access. Group blackboards are only accessible to members of a given Entity Group.

Global Blackboard Mapping [get/set]

Defininitions of connections to global blackboards. Global blackboards are created and managed by AI Managers and can be accessed by any entity registered to a given manager.

Creating Entity Groups

The following code sample shows an example of how to create an Entity Group and register it to an AI Manager. Typically, a better way is to use configuration files (see this page), but sometimes it makes sense to create them from code, if you want to use some custom logic.

  • C++

  • C#

std::vector<std::shared_ptr<grail::AIEntity>> entities{};

for(const auto& entityName : entityNames) { auto entity = std::make_shared<grail::AIEntity>(entityName); entity→AddSharedBlackboard(sharedBlackboardName, sharedBlackboard); entities.push_back(entity); }

std::vector<grail::EntityEntry> entityEntries{}; for(const auto& entity : entities) { entityEntries.emplace_back(entity, 0); // 0 is the highest priority }

auto entityGroup = std::make_shared<grail::EntityGroup>(groupName, entityEntries);

const std::string sharedBlackboardName = "shared"; auto sharedBlackboard = std::make_shared<grail::Blackboard>(); entityGroup→AddGroupBlackboard(sharedBlackboardName, sharedBlackboard);

sharedBlackboard→SetValue<int>("int_param", 1); sharedBlackboard→SetValue<float>("float_param", 3.2f);

grail::AIManager manager; const std::string gameDataBlackboardName = "game_data"; manager.CreateBlackboard(gameDataBlackboardName); for(const auto& entityEntry : entityGroup→GetEntityEntries()) { entityGroup→AddGlobalBlackboardMapping(entityEntry.entity, {gameDataBlackboardName}); }

manager.RegisterEntityGroup(entityGroup, 0); // Register entity group with priority 0

List<AIEntity> entities = new List<AIEntity>();

foreach (var entityName in entityNames) { AIEntity entity = new AIEntity(entityName); entity.AddSharedBlackboard(sharedBlackboardName, sharedLocal); entities.Add(entity); }

List<(AIEntity entity, int priority)> entityEntries = entities.Select(entity ⇒ (entity, 0)).ToList(); // 0 is the highest priority

EntityGroup entityGroup = new EntityGroup(groupName, entityEntries.ToArray());

string sharedBlackboardName = "shared"; Blackboard sharedLocal = new Blackboard(); entityGroup.GroupBlackboards.AddsharedBlackboardName, sharedLocal;

sharedLocal.SetValue("int_param", 1); sharedLocal.SetValue("float_param", 3.2f);

AIManager manager = new AIManager(); string gameDataBlackboardName = "game_data"; manager.CreateBlackboard(gameDataBlackboardName); foreach (var (entity, priority) in entityGroup.EntityEntries) { entityGroup.GlobalBlackboardMapping.Addentity, new List<string> { gameDataBlackboardName }; }

manager.RegisterEntityGroup(entityGroup, 0); // Register entity group with priority 0