vedaloivdocs

Guide

Culling and NavMesh

Documentation for v1.1.0AI Navigation 2.0.13Unity 6000.5.0+

After a dungeon is generated, post-processors run on the same GameObject as the DungeonManager. Two of them are optional: DungeonCulling hides rooms the player cannot reach or see, and DungeonNavMeshPostProcessor bakes one NavMesh over the whole dungeon.

On this page
  1. Post-processing order
  2. Portal culling
  3. NavMesh
  4. Burst planner
  5. Common mistakes

Post-processing order#

The manager runs every enabled post-processor, highest Priority first. Processors with the same priority keep their order on the component list, except that DungeonCulling always runs last among them.

ComponentDefault priorityRole
DungeonNavMeshPostProcessor0Bakes the NavMesh from the generated rooms.
DungeonCulling−100Hides rooms. Runs after the bake, so the bake still includes every room.

Portal culling#

Culling hides rooms that are far away or behind doors that are closed. It does not change the dungeon itself. Removing the component restores the normal behavior.

  1. Select the DungeonManager and click Add Culling Support. This adds DungeonCulling.

  2. Set Mode. It is Disabled by default, so nothing is hidden until you change it. Choose DisableRenderers for the cheapest option, or DeactivateRooms to switch the whole room off.

  3. Set Reference Transform to the camera or the player. Culling is measured from this object.

  4. Generate and play. Turn on Debug Draw to see visible rooms in green and hidden rooms in red in the Scene view.

mode Disabled, DisableRenderers, or DeactivateRooms default Disabled
DisableRenderers stops rendering hidden rooms, and their scripts and physics keep running. DeactivateRooms turns the room GameObject off, which also saves updates and physics. Switching many rooms back on at once can cause a short hitch.
cullLights bool default on
Also turns off the lights of hidden rooms. Used only in DisableRenderers mode.
maxHops int default 4
How many doors away from the reference room a room may be and stay visible. 0 or a negative value means no limit.
occlusionTolerance int default 0
How many closed or locked doors a room may lie behind and stay visible. 0 hides everything behind the first closed door.
viewDistance float default 60
Rooms farther than this from the reference point are hidden, even when reachable. 0 or a negative value means no distance limit.
revealDistance float default 45
Distance at which a hidden room becomes visible again. It is smaller than viewDistance, so rooms at the edge do not flicker.
protectedNeighborHops int default 1
Rooms this many hops from the reference room stay visible, even behind a closed door.
maxVisibleRooms int default 0
Budget of visible rooms, kept by a deterministic score. 0 means no budget.
pollInterval float default 0.25
Seconds between checks of the door states and the reference position. 0 checks every frame.
maxTogglesPerFrame int default 20
Rooms switched per frame, spread over frames to avoid spikes.
referenceTransform, referencePosition, useReferencePosition
The reference is the transform if set, otherwise the fixed position when useReferencePosition is on, otherwise a registered local viewpoint or the main camera. With no viewpoint at all, every room stays visible.
debugDraw bool default off
Draws the rooms and connections in the Scene view.

A connection is passable only when both of its doors are open and unlocked. Each mechanism above can be switched off in the Mechanism Toggles section, for example useMaxHops or useDistanceCulling.

To add your own rules, implement ICullConnectionRule (decides whether a connection is passable) or ICullRoomRule (forces a room visible or hidden). AcquireVisibility keeps a room visible while gameplay needs it. See the API Reference.

The NavMesh post-processor bakes one NavMesh that covers the whole dungeon, on every floor, after each generation. It needs the AI Navigation package, version 2.0.13.

  1. Select the DungeonManager and click Add NavMesh Support. This adds DungeonNavMeshPostProcessor with its host and a NavMeshSurface.

  2. Check layerMask. Room floors, walls, and stairs must be on the layers in this mask. The default is the Default layer.

  3. Generate. The baked NavMesh is ready when the generation is done. Use logErrors to see why a bake was skipped.

agentTypeID int default 0, Humanoid
The agent type to bake for. Agent types are set in Project Settings › Navigation.
boundsPadding float default 1
Extra space in meters on each side of the dungeon bounds.
layerMask LayerMask default Default
Layers whose colliders are baked.
buildOnProcess bool default on
Bakes after each generation. Turn it off to bake yourself.
useDoorLinks bool default on
Adds a NavMeshLink at connections the NavMesh does not already cross, for example two floor areas that are not joined.
linkEndpointInset, linkSearchRadius, linkWidth float default 0.3, 1.5, and 1.5
Where a link starts, how far it may move to reach the NavMesh, and how wide it is.
bakeConnectors bool default off
Bakes temporary bridges across doorways instead of adding links. The NavMesh is then continuous through the doors. Overrides useDoorLinks.
connectorWidth float default 1.6, minimum 0.1
Width of the bridges. Keep it narrow enough to avoid false corner merges, but wide enough to survive the agent's erosion.
logErrors bool default on
Logs why a bake cannot run: a missing host, no rooms, no colliders, or data it does not own.

Clear or regenerate the dungeon and the NavMesh is released first, then rebuilt for the new layout. A NavMesh that you bake yourself on the same objects is never touched.

Burst planner#

The Use Burst Planner option (useBurstPlanner on the DungeonManager, default off) runs the DFS placement search as Burst-compiled code.

  • It is a separate implementation of the planner. The same seed can give a different valid layout than the managed planner. If a seed must keep its layout across builds, keep the same planner setting.
  • Burst, Collections, and Mathematics are needed to compile the package even when the option is off.

Common mistakes#

  • Culling does nothing. The mode is Disabled by default. Set Mode, and check that Reference Transform is assigned.
  • Hidden rooms are missing from the NavMesh. Culling runs before the bake. Lower the culling priority, as described in Post-processing order.
  • The bake fails with a read-access error. The room meshes do not allow read access. Turn on Read/Write in each model's import settings, or replace the mesh colliders with box colliders as the demo does. See Troubleshooting.
  • Clicks miss the floor. Agents move only to points on the NavMesh. Check the bake in the Console, and that any roof or ceiling collider is off.