When you have multiple sectors in a terrain they are likely to overlap, at least around their edges. This overlap may affect the navigable areas in one or both of the sectors.
The NavData generation system identifies these areas of overlap and gives them special treatment in order to ensure that the NavData correctly reflects the geometry that is loaded into memory.
Each sector needs to be configured with a globally unique ID represented by an instance of the KyGuid class, which you provide when you create the sector.
For example, consider a sector that contains a relatively flat plain, and an adjacent sector that contains a hill. The geometry in the two sectors overlaps slightly, so that a little of the hill projects below the level of the plain, and a little of the plain extends below the hill.
When only the NavData for the plain is loaded, its NavData reflects the flat terrain. When only the hill is loaded, its NavData reflects only the hillside. When both sectors are loaded at the same time, the parts of the plain and the hill that overlap are automatically replaced by the alternative chunk that represents the overlap area, allowing a bot to pass from one sector to the next.
This process is entirely transparent. All you have to do is provide all your different sectors in the same run of the NavData generation system; the generation and runtime stitching of the overlap data will be handled automatically.
The automatic overlap detection and stitching system is designed to seamlessly handle every combination of sectors to ensure that the NavMesh is always consistent with the geometry of whatever set of sectors are currently loaded into the game, even along the borders between sectors.
However, in some scenarios, you may want to prevent the generation of overlap data in order to decrease the memory footprint of the NavData for your sectors. The scenarios that typically allow for disabling the generation of overlap data without compromising the accuracy of the NavMesh are described below.
Sometimes, when major changes can occur in a terrain geometry during the course of a game, you may want to generate NavData for that sector in two different states, and swap them at runtime when the state of the terrain changes. The classic example of a swappable sector is an area with a large building that can be destroyed at runtime. While the building is in place, you want characters on the ground to walk around it, and you may even want characters to be able to move around inside the building, on the roof, etc. However, when the building gets destroyed, the characters should be free to move along the ground through the area formerly occupied by the building.
You can create the NavData for these swappable sectors transparently by setting up a different sector for each state of the geometry, and generating both sectors at the same time along with the rest of the sectors in your world. For example, you would create one sector that contains the geometry of the terrain with the building intact, and another sector that contains the geometry of the terrain after the destruction of the building. The Generator will transparently take care of creating NavData for both versions of the swappable sector, and creating overlap data that link both versions to the surrounding sectors.
However, by default the NavData generation system will consider it possible for the two versions of the swappable sector to be streamed into memory at the same time. It will detect that the two sectors overlap in space, so in addition to creating a NavMesh for each sector on its own, it will also create overlap data that covers the whole area of the swappable sector for the combination of the geometry. This is not a problem, in that the system will still work smoothly at runtime: whichever sector you have loaded at any time will always have a NavMesh that correctly represents the terrain. However, in the case of swappable sectors, you know that the overlap data will never be needed, since the two versions of the swappable sector will never be loaded at the same time. You can therefore save memory by preventing the NavData generation system from creating the overlap data in the first place.
To set up exclusive sectors in the Navigation Lab:
Each time you check the box for a sector, an Activate button appears. Click this button if desired in order to show only that sector in the 3D view.
Note that the name of your "ExclusiveSectors" element in the Scene View has been updated to indicate which sectors it manages.
You can set up as many different sets of exclusive sectors as you need.
You can inform the Generator which sectors will never be loaded at the same time by providing the KyGuids of those sectors in a call to GeneratorInputOutput::AddExclusiveGuids(). The Generator will not generate any overlap data for that combination of sectors. You can call this method as many times as necessary to set up different sets of exclusive sectors.
Some game projects use streaming sub-levels whose extents adhere to a regular axis-aligned grid with a consistent length and width for each cell. If your project uses such a grid to lay out the divisions between adjacent sub-levels, you can avoid the generation of unnecessary overlap data by using cell boxes to define the extents of your sectors.
In this approach, you align the cell size used internally by the NavData generation framework with the size of your grid cells. For each sector, you provide the extents of a box that defines which cells will be assigned to that sector.
Note that because each NavData cell always reflects the combination of all overlapping geometries, but each cell is stored in only one of the sectors, you may see localized inconsistencies between the NavData and the geometry within areas of overlap if you load the terrain mesh for only one of the overlapping sectors into the game.
To determine the extents of the cell box to use for each sector, you can:
For a code example, see the Tutorial_Generation_cellbox.cpp file.
You can toggle the rendering of the cell boxes in the 3D view by toggling the CellBoxes button in the Generation Inputs toolbox.