AI Territories and Waves (T/W) help Level Designers to control the number of active AIs (AI entities) at any time in the game using simple flowgraph logic. T/W should not be used for vehicle AI.
A Territory is a shape that defines an area. All AIs assigned to a Territory can be activated, deactivated, and spawned with a single flownode. Optionally, Waves are contained in Territories and allow independent AI activations inside a Territory.
T/W allow Level Designers a much easier and faster setup for AI in their levels and significantly speed up debugging AI flowgraph issues. Controlling AI with this system also helps designers to not exceed the maximum number of allowed active AIs. This is especially important on consoles.
AI Territories and Waves (T/W) help Level Designers to control the number of active AIs (AI entities) at any time in the game using simple flowgraph logic. T/W should not be used for vehicle AI.
A Territory is a shape that defines an area. All AIs assigned to a Territory can be activated, deactivated, and spawned with a single flownode. Optionally, Waves are contained in Territories and allow independent AI activations inside a Territory.
T/W allow Level Designers a much easier and faster setup for AI in their levels and significantly speed up debugging AI flowgraph issues. Controlling AI with this system also helps designers to not exceed the maximum number of allowed active AIs. This is especially important on consoles.
A simple example of T/W usage would be:
It's a collection of empty slots with which an entity of a given type can be prepared from. It's a way to control the number of entities that exist in memory.
An entity pool is created by filling the slots with a specific number of "empty" entities of a given type - AI, vehicle, item, rigid body, etc... The intention is to reuse these slots over and over for all the entities of that type which exist in the world, bringing them into existence when they're needed and removing them when they're not so that others may be used in place. Where as before, a level may have created over 100 AI entities and only use 8 to 16 of them at a time. While only these that are being used are being drawn and updated, the other AI entities still exist in memory and are looked at by the game at various moments (such as saving and loading). When using a pool, we remove those excesses from memory by ensuring only 16 (or however large the pool is) ever exist in memory.
When an entity is set to go through an entity pool, it is not created when the level is loaded. Instead, the information specific to it is saved. When the entity is later needed during the progression of the game, the entity is prepared from the pool. When the entity is no longer needed, it is freed back to the pool.
When an AI entity is marked as being created through the pool and it is used inside of an AI Wave, you do not need to manually prepare or free this AI! Instead, you only have to enable/spawn the AI Wave. All pooled AI entities inside that wave will then be prepared and enabled for you, resulting in consistent behavior as expected with AI Waves. Furthermore, if you disable the AI Wave, all pooled AI entities inside that wave will be freed. With this in mind, your existing Flowgraph for controlling the AI Wave should be sufficient enough to deal with the AI entities inside being pooled.
When an AI has been killed, the AI entity does not need to be freed right away. A dead AI is placed in a go-between state: it is still taking up a slot in the pool, but if a slot is desperately needed, the slot containing the dead AI will be automatically freed and used by the system. If there is more than 1 AI dead, the furthest one away from the player will be used instead. Dead AI does not need to be freed!
However, it is still a good idea to free any AI (by either disabling the AI Wave they are in or manually freeing them) when they are no longer needed, such as when the player has moved on to the next action bubble or entered a point in the level where he cannot backtrack any further. Doing so helps the system out, and that's a good thing.
Properties:
Property | Description |
---|---|
Height | Defines the height, if used as a 3D Territory |
DisplayFilled | Defines if the shape is drawn filled or not, like in AreaShapes |
Shape Parameters | The Territory shape can be edited like AreaShapes. Waves need to be picked in the same way as triggers are picked from AreaShapes. |
Assigned AIs | Displays the number of AIs which are assigned to this Territory |
Select Assigned AIs | By pressing this button, all assigned AIs will be selected, the Territory itself will be deselected |
Flownode:
Input | Description |
---|---|
Disable | Disable the Territory |
Enable | Enable the Territory |
Kill | Kills all active AIs of this Territory |
Spawn | (Re-)Spawn AIs assigned to this Territory (but not assigned to any Wave) |
Output | Description |
ActiveCount | Outputs the number of currently active AIs assigned to this Territory. |
BodyCount | Outputs the number of killed AIs assigned to this Territory. |
Dead | Fires when all AIs assigned to this Territory are dead (works also for respawned AIs). |
Disabled | Fires when the Territory gets disabled (it doesn't fire on level start, although all Territories are disabled from start automatically). |
Enabled | Fires when the Territory gets enabled. |
Spawned | Fires when AIs are spawned via the Spawn input (if the Territory was disabled before, it gets enabled and the Enabled output fires as well). |
Properties:
Property | Description |
---|---|
Assigned AIs | Displays the number of AIs which are assigned to this Wave. |
Select Assigned AIs | By pressing this button, all assigned AIs will be selected, the Wave entity itself will be deselected. |
Flownode:
Input | Description |
---|---|
Disable | Disable the Wave |
Enable | Enable the Wave |
Kill | Kills all active AIs of this Wave |
Spawn | (Re-)Spawn AIs assigned to this Wave |
Output | Description |
ActiveCount | Outputs the number of currently active AIs assigned to this Wave |
BodyCount | Outputs the number of killed AIs assigned to this Wave |
Dead | Fires when all AIs assigned to this Wave are dead (works also for re-spawned AIs) |
Disabled | Fires when the Wave gets disabled (it doesn't fire on level start, although all Waves are disabled from start automatically) |
Enabled | Fires when the Wave gets enabled |
Spawned | Fires when AIs are spawned via the Spawn input (if the Wave was disabled before, it gets enabled and the Enabled output fires as well) |
Property | Description |
---|---|
Territory | Assigns the AI to a Territory:
|
Wave | Assigns the AI to a Wave:
|
To mark an entity as going through a pool, you need to tick its 'Created Through Pool' property as true. This can be done either through the Archetype or on each individual entity via its Params on the Rollup Bar. The latter overrides the former's setting.
When the level is loaded in the Launcher, the entity will be correctly setup to work with the pool if a pool exists to handle it. If not, the entity will be created as normal.
The 'HiddenInGame' property can be used in conjunction. If this is not ticked (set to FALSE), the entity will be automatically prepared from the pool on level start. If ticked (set to TRUE), the entity will not be prepared until you explicitly call on it via Flowgraph (see below).
ai_DebugDrawEnabledPuppets 1 Displays all enabled AIs and their Territories & Waves in the center of the screen
ai_DebugDrawTerritoriesAndWaves 1 Displays Territory & Wave below each AI (_ai_DebugDraw_ needs to be on)
ai_StatsDisplayMode 1 Not related to T/W but very useful to check the number of currently active AI
How do I know if my level is prepared for Entity Pools?
Simple! First, open your level in the game launcher. Once loaded, type the following into your console:
es_DebugPool 1
You will see a bunch of text appear in the top-left corner. One of the lines will mention "Bookmarked Entities" and have a count beside it.
If you know there are AI or other entities in your level which should have their "Created Through Pool" option ticked to true and this count is higher than 0, then the level is prepared and ready to go!
If the count is at 0, then the level is not prepared for entity pooling. In such a case, try the following:
How do I know if the pool is full in my level?
This may also interest you if you want to see how the entity pool is being utilized in your level. First, open your level in the game launcher. Once loaded, type the following into your console:
es_DebugPool 1
es_DebugPoolFilter AI
... where 'AI' should be replaced with the name of the entity pool you want to test. The names of all pools will be visible if you keep "es_DebugPoolFilter" cleared.
What you should see is a bunch of text in the top-left corner of your screen. The pool's information and contents will be displayed.
The following are the useful bits to take from this output: