# Wall Generation

Walls are how you tell the crowd where it **cannot** go. Internally the simulation keeps a
**wall grid**: a coarse grid of square tiles (size = `WallTileSize`) that are either open or
blocked. Blocked tiles both **block pathfinding** (routes go around them) and, when
`bWallCollision` is on, **physically stop agents** from entering.

::: tip
The wall grid is independent of the [pathfinding](../concepts/01-navigation.md) tile grid.
`WallTileSize` controls how finely obstacles are represented; `PathTileSize` controls routing
resolution.
:::

## Seeding walls from the nav mesh

The easiest way to get walls that match your level is to mirror Unreal's **navigation mesh**.
The crowd actor's **Wall Generation Method** defaults to **Nav Mesh**, so the walls are built
automatically on `BeginPlay`.

![Wall Generation Method set to Nav Mesh](../assets/get-started/walls-method-dropdown.png)

What happens: the built nav mesh is rasterized into the wall grid - every `WallTileSize` cell
whose centre is **not** covered by a navigable triangle becomes a wall. So holes, static
obstacles and unnavigable regions in the nav mesh become walls in the crowd sim.

![Generated wall tiles over the level](../assets/get-started/walls-debug.png)

!!!
This requires the nav mesh to be **built**. Add a **Nav Mesh Bounds Volume** to your level (and
a `RecastNavMesh` actor) covering the playable area, the same as you would for normal UE
navigation.
!!!

==- Sealing the outer border
By default only **enclosed** unwalkable areas (holes and obstacles surrounded by walkable mesh)
become walls - the outer edge of the nav mesh stays open. Enable
**`bGenerateNavMeshBorderWalls`** to also wall off the region along the nav mesh's outer border
(plus a one-tile fence past its rim), sealing agents inside the navigable area.
===

### Regenerating at runtime

`GenerateWallTilesFromNavMesh()` is callable directly, so you can rebuild walls at any time
(e.g. after rebuilding the nav mesh) regardless of the **Wall Generation Method** setting. It
returns the number of wall tiles added and is safe to call repeatedly - adding a tile that
already exists is a no-op.

![Generate Wall Tiles From Nav Mesh node](../assets/get-started/walls-generate-node.png)

==- C++
```cpp
int32 Added = Crowd->GenerateWallTilesFromNavMesh();
```
===

## Stamping walls at runtime

You can also add wall tiles directly, by **grid coordinate**, without any nav mesh. This is the
building block for "place a building, the crowd reroutes around it": convert the building's
footprint to tile coordinates and stamp those tiles.

![Add Wall Tile node](../assets/get-started/walls-add-tile.png)

==- C++
```cpp
// Block the tile at grid (X, Y). Coordinates are in wall-tile units.
Crowd->AddWallTile(10, 4);

// Read back every wall tile (e.g. to visualise the grid):
TArray<FIntPoint> Tiles = Crowd->GetWallTiles();
```
===

Newly added walls invalidate the affected pathfinding caches, so existing orders re-route on
the next move.

::: warning
Wall **removal** and an actor-driven obstacle component are on the roadmap (v1.x). In 1.0, walls
are added, not removed - to clear them, [reset the simulation](../api_reference/01-crowd_actor.md#simulation-control)
and re-seed.
:::

## Tuning how the crowd treats walls

| Property | Effect |
|---|---|
| **Has Collision** (`bWallCollision`) | Master switch for *physical* wall blocking. Off = walls still block pathfinding but agents can pass through them. |
| **Tile Size** (`WallTileSize`) | World units per wall tile. Smaller = obstacles represented more precisely, more tiles. |
| **Near Wall Cost** (`NearWallCost`) | Pathfinding traversal multiplier for open cells touching a wall. Higher pushes routes away from walls (agents hug corners less). `1` disables the bias. |

See the [Crowd Actor reference](../api_reference/01-crowd_actor.md#walls) for the full property
list.
