> For the complete documentation index, see [llms.txt](https://heroicsolo.gitbook.io/heroic-engine/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heroicsolo.gitbook.io/heroic-engine/basics/publish-your-docs/gameplay-systems/dungeon-generator.md).

# Dungeon Generator

Presented by `IDungeonGenerator` interface, this system allows to generate dungeons of needed size and complexity by maens of BSP algorithm.

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FiotHBFbpBojjlKChzwxd%2Fimage.png?alt=media&amp;token=8b1d255a-30d4-4750-a6b7-278a4375c9b3" alt=""><figcaption><p>Dungeon generation</p></figcaption></figure>

To use it, you can just drag `DungeonGenerator` prefab onto your game scene and set it up as you want.

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2F41lqCk7DaZQDTKIX26mE%2Fimage.png?alt=media&amp;token=f2a309b1-4394-403c-963d-c38499891891" alt=""><figcaption><p>DungeonGenerator prefab</p></figcaption></figure>

### Parameters in inspector

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FeyAb1s2taLipkJ4d2vre%2Fimage.png?alt=media&amp;token=7099f07d-1664-4348-a27a-ce5248e0b607" alt=""><figcaption><p>Parameters in inspector</p></figcaption></figure>

**Floor Tile Prefabs** – list of floor tile prefabs. You can add your own tiles here, they should be gameobjects with width and length equal to 1 unit, height can have any value.

**Wall Tile Prefabs** – list of wall tile prefabs. You can add your own tiles here, they should be gameobjects with width and length equal to 1 unit, height can have any value.

**Enable Walls** – if set to true, walls will be generated, otherwise, dungeon will be only with floor tiles.

**Dungeon Width** – width of dungeon, 50 units by default.

**Dungeon Length** – length of dungeon, 50 units by default.

**Min Room Size** – minimal room size in units.

**Max Iterations** – max number of rooms splitting iterations.

**Room Margin** – margin between rooms in units.

**Corridor Width** – typical width of corridor in units.

***

You can also use its functionality via code. For this, inject IDungeonGenerator interface into your class.

### Available methods

```csharp
List<DungeonRoom> GenerateDungeon(Vector3 pos)
```

*This method generates dungeon with default settings set in DungeonGenerator inspector.*

***

```csharp
List<DungeonRoom> GenerateDungeon(Vector3 pos, int width, int length)
```

*This method generates dungeon with default settings set in DungeonGenerator inspector, but with custom width and length.*

***

```csharp
List<DungeonRoom> GenerateDungeon(Vector3 pos, int width, int length, 
    bool enableWalls = true, int minRoomSize = 5, int roomMargin = 2, 
    int maxIterations = 5)
```

*This method generates dungeon with custom settings.*

*Example:*

```csharp
dungeonGenerator.GenerateDungeon(playerPos, 40, 40, true, 6, 2, 4);
```

***

```csharp
void ClearDungeon()
```

*This method clears current dungeon. Automatically called when new dungeon is being generated.*

***

```csharp
void GenerateNavMesh()
```

*This method generates NavMesh for current dungeon.*
