2.6+

Introduction

Dungeon Architect is a plugin for Unreal Engine 4 Editor that lets you quickly build procedural levels for your games. This guide helps you work with the plugin using C++

Project Setup

Add Dungeon Architect to your game project’s Build.cs file so you can access the plugin

Setup Project.Build.cs

Setup Project.Build.cs

Open the file **Source/PROJECT_NAME/PROJECT_NAME.Build.cs**

Add DungeonArchitectRuntime to the list of PublicDependencyModuleNames

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class PROJECT_NAME : ModuleRules
{
    public PROJECT_NAME(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay",
            "DungeonArchitectRuntime" });
    }
}

Build at runtime

Build a random dungeon at runtime. This assumes that you have a dungeon in your level with the themes already setup.

The code sample is placed in the GameMode class on StartPlay

GameMode Header file

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "DA416XGameMode.generated.h"

UCLASS(minimalapi)
class ADA416XGameMode : public AGameModeBase
{
    GENERATED_BODY()

public:
    ADA416XGameMode();

    virtual void StartPlay() override;
};

GameMode Source file

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "DA416XGameMode.h"
#include "DA416XCharacter.h"
#include "UObject/ConstructorHelpers.h"

#include "EngineUtils.h"        // for TActorIterator
#include "Dungeon.h"
#include "GridDungeonConfig.h"


ADA416XGameMode::ADA416XGameMode()
{
    // ...
}

void ADA416XGameMode::StartPlay()
{
    Super::StartPlay();

    // Find the dungeon actor from the scene
    TActorIterator DungeonIter = TActorIterator(GetWorld());

    if (DungeonIter) {
        ADungeon* Dungeon = *DungeonIter;

        // grab the config so we can change it before building
        UDungeonConfig* Config = Dungeon->GetConfig();

        // If we want to set a specific builder config (like grid / floorplan etc.) cast to the appropriate config object
        if (UGridDungeonConfig* GridConfig = Cast(Config)) {
            GridConfig->Seed = FMath::Rand();   // Generate a new dungeon every time with a random seed
            GridConfig->NumCells = 100;         // Set a grid config specific property
            // Set you other properties here
        }

        // Build the dungeon
        Dungeon->BuildDungeon();
    }
}