Skip to content

Instantly share code, notes, and snippets.

@coderespawn
Created September 19, 2016 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderespawn/6138dd751276701cdbfb4216c1a8cf19 to your computer and use it in GitHub Desktop.
Save coderespawn/6138dd751276701cdbfb4216c1a8cf19 to your computer and use it in GitHub Desktop.
template<typename T>
T* GetAsset(const FName& Path) {
UObject* Obj = StaticLoadObject(UDungeonThemeAsset::StaticClass(), nullptr, *Path.ToString());
return Cast<T>(Obj);
}
void ADA413XGameMode::BuildDynamicDungeon() {
// Create a new dungeon actor
Dungeon = GetWorld()->SpawnActor<ADungeon>(ADungeon::StaticClass());
// Grab a reference to the theme asset and register it with the dungeon actor
UDungeonThemeAsset* MyTheme = GetAsset<UDungeonThemeAsset>("/Game/DA_Candy/Themes/D_Candy_v2"); // Set your theme path here
Dungeon->Themes.Add(MyTheme);
// Set the builder type
Dungeon->BuilderClass = UGridDungeonBuilder::StaticClass();
Dungeon->CreateBuilderInstance();
// Set the dungeon configuration
UGridDungeonConfig* GridConfig = Cast<UGridDungeonConfig>(Dungeon->GetConfig());
if (GridConfig) {
GridConfig->Seed = FMath::Rand(); // Randomize our dungeon
// Set other grid config here
}
Dungeon->BuildDungeon();
}
void ADA413XGameMode::StartPlay() {
Super::StartPlay();
BuildDynamicDungeon();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment