Class NavigationBuilder
Manages NPC navigation for building interiors.
Carves the building footprint from baked NavMesh using NavMeshObstacle,
then provides custom A* pathfinding for interior navigation.
A Harmony patch on NPCMovement.SetDestination automatically intercepts NPCs
whose destinations fall inside the building — no manual SendNPCTo calls needed.
NPCs seamlessly transition between exterior NavMesh and interior A* pathfinding.
public sealed class NavigationBuilder
- Inheritance
-
NavigationBuilder
- Inherited Members
Remarks
Call Build() after the building is positioned in the scene. Call Rebuild() when interior objects change (e.g. furniture moved). Call Remove() when the building is destroyed.
Constructors
NavigationBuilder(Transform, Vector3, IReadOnlyList<NavDoorwayInfo>, float, float)
Create a new navigation builder for a building.
public NavigationBuilder(Transform buildingRoot, Vector3 roomSize, IReadOnlyList<NavDoorwayInfo> doorways, float wallThickness, float foundationHeight = 0)
Parameters
buildingRootTransformRoot transform of the building (must be positioned before calling Build)
roomSizeVector3Interior room dimensions (width, height, depth)
doorwaysIReadOnlyList<NavDoorwayInfo>Doorway positions for source filtering and ramp generation
wallThicknessfloatExterior wall thickness in meters.
foundationHeightfloatFoundation height in meters (0 = no foundation).
Properties
CellSize
Grid cell size in meters. Matches the resolution used by interior pathfinding so callers can iterate cells at the same spacing. Returns 0.5 when the navigation system has not been built yet.
public float CellSize { get; }
Property Value
IsBuilt
Whether the NavMesh is currently active.
public bool IsBuilt { get; }
Property Value
Methods
Build()
Set up interior NPC navigation for this building.
Carves baked NavMesh under the footprint and installs a custom A*
pathfinding grid. NPCs whose SetDestination targets fall inside the
building are automatically intercepted and navigated through the interior.
Must be called after the building is positioned in the scene.
public void Build()
DiagnoseCell(int, int)
Diagnose why a specific grid cell is blocked. Logs the blocking reason (wall margin, interior wall, physics collider name) to the console. Cell coordinates are visible in the visualization quad names (Cell_X_Z).
public void DiagnoseCell(int gridX, int gridZ)
Parameters
IsNPCInside(Component)
Check if an NPC is currently being managed by this building's interior navigator.
public bool IsNPCInside(Component npc)
Parameters
npcComponentThe NPC component to check.
Returns
IsWalkable(Vector3)
Check if a local-space position is on a walkable grid cell. Returns false when the navigation system has not been built yet.
public bool IsWalkable(Vector3 localPos)
Parameters
localPosVector3Position in building-local coordinates.
Returns
- bool
True if the cell at
localPosis walkable.
LocalToWorld(Vector3)
Convert a building-local position to world-space coordinates.
public Vector3 LocalToWorld(Vector3 localPosition)
Parameters
localPositionVector3The building-local position to convert.
Returns
- Vector3
NearestWalkableCell(Vector3)
Get the center of the nearest walkable grid cell in local coordinates.
Returns localPos unchanged when the navigation system has not been built yet.
public Vector3 NearestWalkableCell(Vector3 localPos)
Parameters
localPosVector3Position in building-local coordinates.
Returns
- Vector3
The center of the nearest walkable cell, or
localPosif unavailable.
Rebuild()
Tear down and rebuild the NavMesh. Use when interior objects change (e.g. furniture placed or moved).
public void Rebuild()
RecallNPC(Component)
Recall an NPC from the building. If inside, begins exit via A* path to doorway. If still approaching, releases immediately. The NPC's NavMeshAgent is re-enabled on exit.
public void RecallNPC(Component npc)
Parameters
npcComponentThe NPC's NPCMovement component.
Remove()
Remove all NavMesh data and cleanup. Call when the building is destroyed.
public void Remove()
SendNPCToPosition(Component, Vector3, Action?)
Send an NPC to a position inside the building. The NPC walks to the nearest doorway on exterior NavMesh, enters via lerp, then follows A* path to target.
public void SendNPCToPosition(Component npc, Vector3 localTarget, Action? onArrival = null)
Parameters
npcComponentThe NPC's NPCMovement component.
localTargetVector3Target position in building-local coordinates (0,0 = building corner).
onArrivalActionOptional callback invoked when the NPC reaches the destination.
VisualizePathGrid(bool)
Show or hide the interior pathfinding grid visualization. Green cells are walkable, red cells are blocked.
public void VisualizePathGrid(bool show = true)
Parameters
showboolTrue to show the grid, false to hide it.
WorldToLocal(Vector3)
Convert a world-space position to building-local coordinates. Use this to convert world positions (e.g. furniture transforms) to the local coordinates expected by SendNPCToPosition(Component, Vector3, Action?).
public Vector3 WorldToLocal(Vector3 worldPosition)
Parameters
worldPositionVector3The world-space position to convert.
Returns
- Vector3