The big question when designing modular behaviors is how to manage their information and computation. There are certain aspects that need to be private or hidden from the rest of the AI engine, while other aspects must be public so that they can be freely accessed. In the second case, it’s also useful to know which interfaces are required and which are optional.
Structuring the Data
- Internal Memory
- Many behaviors use their own memory to accomplish a task. Generally, this is expected to be private, though specific interfaces can be exposed to allow the AI engine to read parts of it if necessary.
- Shared Information
- Each behavior must support running on multiple different actors, and in each case optionally uses new memory. This is called instance-specific data, since behaviors are “instantiated” when applied to actors.To avoid unnecessarily wasting memory, all the information that’s in common with all actors should only be stored once. This is called shared data. Most configuration settings for the behaviors can be placed here.
Designing the Computation Interface
- Invocation, Execution
- Since behaviors must be able to run over multiple frames, the code needs to be split into small chunks. Once this is in place, it’s much easier to allow behaviors to run in parallel. Also, having a common API also helps here as it can be easier to work with — and manage centrally.
- Terminating and Return Codes
- Most often, it’s also necessary for each behavior to use a return status once it has finished. The code explains how the computation finished and if there was an error or not. This information is typically passed by a public interface, so that the AI engine can deal with all eventualities.
Taking all these considerations together, we end up with:
A simple interface for invoking and running behaviors. This is typically a common interface for all behaviors.
A way for behaviors to reuse data that is shared among multiple actors.
A facility for extracting custom information from behaviors, i.e. a public interface but not used commonly.
The rest of the information and computation is hidden from the AI engine.
There are also a few things to watch out for when doing this…