Table of Contents

Class NavigationBuilder

Namespace
S1MAPI.Building
Assembly
S1MAPI_Mono.dll

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

buildingRoot Transform

Root transform of the building (must be positioned before calling Build)

roomSize Vector3

Interior room dimensions (width, height, depth)

doorways IReadOnlyList<NavDoorwayInfo>

Doorway positions for source filtering and ramp generation

wallThickness float

Exterior wall thickness in meters.

foundationHeight float

Foundation 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

float

IsBuilt

Whether the NavMesh is currently active.

public bool IsBuilt { get; }

Property Value

bool

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

gridX int

The X coordinate on the interior grid.

gridZ int

The Z coordinate on the interior grid.

IsNPCInside(Component)

Check if an NPC is currently being managed by this building's interior navigator.

public bool IsNPCInside(Component npc)

Parameters

npc Component

The NPC component to check.

Returns

bool

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

localPos Vector3

Position in building-local coordinates.

Returns

bool

True if the cell at localPos is walkable.

LocalToWorld(Vector3)

Convert a building-local position to world-space coordinates.

public Vector3 LocalToWorld(Vector3 localPosition)

Parameters

localPosition Vector3

The 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

localPos Vector3

Position in building-local coordinates.

Returns

Vector3

The center of the nearest walkable cell, or localPos if 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

npc Component

The 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

npc Component

The NPC's NPCMovement component.

localTarget Vector3

Target position in building-local coordinates (0,0 = building corner).

onArrival Action

Optional 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

show bool

True 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

worldPosition Vector3

The world-space position to convert.

Returns

Vector3