Choose Next Room
This function is the main part of the procedural generation: it's where you set your own logic to generate your dungeon.
This function is run each time the generator tries to add a room to the dungeon.
As input parameters:
Current Roomis the room from which the generator will try to add the next room.
For example, the first time this function is called, theCurrent Roomis theRoomDataasset you have returned in theChoose First Roomfunction. [DEPRECATED: useGet Room Dataof theCurrent Room Instanceinput instead]Current Room Instanceis the room instance from which the generator will try to add the next room.
For example, the first time this function is called, theCurrent Room Instanceis theRoominstance created from the room data you have returned in theChoose First Roomfunction.Door Datais the door on which the next room will be connected to.
You have access to its location (expressed in room units, not in unreal units!), its orientation and itsDoorType.
As output:
Return Valueis theRoom Dataasset you want to add as the next room. The value must be non-null and have at least one compatible door withDoor Data.Door Indexis the index of the door (from theRoom Dataasset your return) used to connect with theCurrent Room.
If the index is negative, it will choose a random compatible door.
If you set a value, it will take the door at the same index in yourRoom Dataasset (make sure the door is compatible!)
How to code my specific use case?
If you struggle to write the code in this function, I would suggest you to read this page to better understand the process of writing the code for this function.
Here an example of a simple dungeon made by NbRoom randomly chosen standard rooms before setting an exit room:
- Blueprint
- C++

MyDungeonGenerator.h
UCLASS()
class AMyDungeonGenerator : public ADungeonGenerator
{
GENERATED_BODY()
public:
// ...
virtual URoomData* ChooseNextRoomData_Implementation(const URoomData* CurrentRoom, const TScriptInterface<IReadOnlyRoom>& CurrentRoomInstance, const FDoorDef& DoorData, int& DoorIndex) override;
// The following variables are just for example purpose
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Dungeon")
TArray<URoomData*> NormalRooms;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Dungeon")
URoomData* EndingRoom;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Dungeon")
int32 MinNbRoom;
// ...
}
MyDungeonGenerator.cpp
URoomData* AMyDungeonGenerator::ChooseNextRoomData_Implementation(const URoomData* CurrentRoom, const TScriptInterface<IReadOnlyRoom>& CurrentRoomInstance, const FDoorDef& DoorData, int& DoorIndex)
{
// After reaching the minimum number of room, place the end room
if (GetRooms()->Count() >= MinNbRoom)
{
return EndingRoom;
}
// Otherwise, place a random normal room
return GetRandomRoomData(NormalRooms);
}