This is a hands-on tutorial. By the end you'll have a modular dungeon that:
- Auto-aligns when the level loads (no manual nudging)
- Refuses to ship with doorways that open to nothing (validation)
- Can be rebuilt at runtime by spawning new pieces (stretch goal)
We'll use the Modular Kit Snapping Tool for the snap system and any modular dungeon kit you have lying around. Synty's Polygon Dungeon, Quaternius's Free Dungeon Pack, KayKit's Dungeon Remastered — anything with walls, floors, and doorway pieces will work.
Time: ~30 minutes Engine: Unreal Engine 5.7 Skill level: Comfortable with Blueprints; light C++ optional
Prerequisites
- A UE 5.7 C++ project (the plugin has runtime + editor C++ modules)
- The Modular Kit Snapping Tool installed under
Plugins/ - A modular dungeon kit imported. We'll assume you have at least:
- A wall mesh (rectangular, with a clear top/bottom orientation)
- A floor mesh (square)
- A doorway frame (wall with an opening)
If you don't have a kit, grab a free one from Quaternius or KayKit before continuing.
Step 1: Make a base modular piece Blueprint
In the Content Browser, right-click → Blueprint Class → search for ModularPieceActor → name it BP_DungeonPiece_Base.
Open it. The class already has a MeshComponent (StaticMesh) and a bIsAnchor flag. We'll subclass it for each piece type so we can set sensible defaults per type.
Step 2: Subclass for Wall, Floor, and Doorway
Create three child Blueprints, each inheriting from BP_DungeonPiece_Base:
BP_Dungeon_WallBP_Dungeon_FloorBP_Dungeon_Doorway
Open each one and set the MeshComponent's static mesh to the corresponding mesh from your kit.
Step 3: Add snap points
For each piece, you'll add SnapPointComponent instances to mark the connection locations.
Wall (BP_Dungeon_Wall)
A standard rectangular wall connects on its left and right edges (the short ones). Add two SnapPointComponents:
| Component name | Location (relative) | SnapType | SnapDirection | SnapRule |
|---|---|---|---|---|
Snap_LeftEdge | Left edge of wall | Wall | Left (-Y) | Optional |
Snap_RightEdge | Right edge of wall | Wall | Right (+Y) | Optional |
Set SnapRadius = 50.0 on both. The SnapDirection is the outward axis — that is, the direction the connection face points away from the piece.
Floor (BP_Dungeon_Floor)
A square floor connects on all four edges. Add four snap points:
| Component name | SnapType | SnapDirection |
|---|---|---|
Snap_North | Floor | Forward (+X) |
Snap_South | Floor | Backward (-X) |
Snap_East | Floor | Right (+Y) |
Snap_West | Floor | Left (-Y) |
Position each one at the midpoint of its respective edge. All Optional, all SnapRadius = 50.0.
Doorway (BP_Dungeon_Doorway)
A doorway is geometrically a wall, but the doorway opening is something we want to make sure is connected to a corridor or another room — not facing into a void. Two snap points:
| Component name | SnapType | SnapDirection | SnapRule |
|---|---|---|---|
Snap_LeftEdge | Wall | Left (-Y) | Optional |
Snap_RightEdge | Wall | Right (+Y) | Optional |
Snap_DoorOpening | Door | Forward (+X) | MustConnect |
That MustConnect is the magic. If the doorway's opening ends up unconnected, validation will flag it.
Step 4: Place pieces in the level (messy is fine)
Drop a few floor pieces in the level — don't worry about exact alignment. Drop walls roughly along their edges. Drop a doorway somewhere in a wall.
The viewport visualizer will show you what you're working with:
- Cyan dots on wall snap points
- Yellow dots on floor snap points
- Brown dots on door snap points
- Red dots on
MustConnectsnap points that aren't connected yet - 60 cm arrows showing outward direction
- Diamond outlines showing snap radius
If the arrows on your wall pieces are pointing the wrong way (e.g. both pointing inward), you have a SnapDirection set wrong. Fix it before proceeding — wrong outward direction is the #1 cause of pieces refusing to snap.
Step 5: Pick an anchor
Choose one floor piece — usually the one in the center or at the entrance — and tick bIsAnchor = true in its details. This piece will stay put while everything else aligns to it.
If you don't pick an anchor, the first piece registered with the manager will become the implicit anchor. Picking explicitly is clearer.
Step 6: Create a rule set
In the Content Browser, right-click → Miscellaneous → Data Asset → ModularKitRuleSet → name it RS_Dungeon.
Open it and either copy values from the Fantasy Dungeon preset or set:
| Property | Value |
|---|---|
RuleSetName | Dungeon |
GridSize | 300 |
SnapDistance | 75 |
AngleTolerance | 5° |
bEnforceMandatoryConnections | true |
Now add a CompatibilityRules entry:
TypeA = Wall,TypeB = Door,bCompatible = true
This says "Wall snap points and Door snap points can connect to each other." Without this, the MustConnect Door snap on the doorway will never find a partner because corridor walls have Wall-typed snap points, not Door-typed.
Step 7: Add the SnapConnectionManager
Create a new actor in your level — it can be an empty Actor Blueprint, or just any actor you already have. Add a SnapConnectionManager component to it.
In the component's details:
- Set
RuleSetto yourRS_Dungeonasset
That's it for setup.
Step 8: Wire AutoSnapAll on BeginPlay
In the actor that owns the SnapConnectionManager, add this Event Graph logic:
Event BeginPlay
↓
SnapConnectionManager → Auto Snap All In World (Self)
↓
Print String: "Made {ReturnValue} connections"
Save, hit Play. Your messy pieces snap into a clean dungeon.
If pieces are still misaligned, the most likely causes are:
- Outward direction wrong — arrows in the visualizer should point out of each piece, not into it
- Snap radius too small — bump
SnapRadiuson the components orSnapDistanceon the rule set - Type mismatch — a Wall snap won't connect to a Floor snap unless you add a compatibility rule
- Pieces too far apart —
AutoSnapAllwon't bridge huge gaps; place pieces roughly where they belong
Step 9: Wire validation
Drag from the SnapConnectionManager reference and add a node from OnValidationResult. Wire the bIsValid boolean to a Branch:
SnapConnectionManager → OnValidationResult
↓ (bIsValid)
Branch
True → Print String: "Dungeon OK"
False → Print String: "Broken: doorway with no exit"
Then call ValidateStructure() after AutoSnapAllInWorld:
Event BeginPlay
↓
SnapConnectionManager → Auto Snap All In World (Self)
↓
SnapConnectionManager → Validate Structure
Hit Play. If your doorway is connected, "Dungeon OK." If you place a doorway facing a wall, you'll get the broken message.
This is the part you want to wire to your CI or to an editor utility — running validation as part of a level review catches broken doorways before QA does.
Step 10 (stretch): Spawn pieces at runtime
Want a "dungeon rebuilds itself" effect? Spawn pieces dynamically and snap on the fly:
For each PieceClass in PiecesToSpawn:
World → Spawn Actor From Class (PieceClass, RandomLocation, RandomRotation)
↓
SnapConnectionManager → Register Piece (NewPiece)
↓
SnapConnectionManager → Auto Snap All ([NewPiece])
AutoSnapAll accepts a curated list, so you can snap one piece at a time as it spawns. Each new piece tries to connect to whatever's already registered, so the dungeon assembles incrementally.
Wire the OnConnectionMade event to a snap SFX and a brief particle burst at the source snap point's location for a satisfying "click into place" feel.
Common pitfalls
| Symptom | Cause | Fix |
|---|---|---|
| Pieces don't snap at all | Outward direction wrong | Check arrows in visualizer; flip SnapDirection |
| Pieces snap but rotated 180° wrong | Both directions point the same way | One snap should face out, the other should face in (anti-parallel) |
| Doorway never validates | No Wall ↔ Door rule | Add FSnapCompatibilityRule to the rule set |
| Walls refuse to connect to other walls | CompatibleTypes set incorrectly per-component | Clear the per-component list, let the rule set handle it |
| AutoSnapAll moves my anchor | bIsAnchor not ticked | Tick it on the piece you want fixed |
| "Best match" picks the wrong piece | Pieces too close together | Lower SnapRadius or reposition |
Next steps
- Snap Points reference — full property details
- Rule Sets reference — tune the compatibility matrix
- Auto-Snap reference — anchors, ordering, runtime use
- Validation reference —
MustConnect, events, editor signal
Pair this with the Procedural Placement Tool if you want to scatter rocks, torches, and debris inside the dungeon after it assembles. One scatters, the other snaps.
Or grab the whole Complete Arsenal — every StraySpark tool at the deepest discount we offer.