Hello, I wanted to make a simplified version to share. Here are some images that show said inconsistent results:
Here is the code:
void ADungeonManager::GenerateRooms(int32 SelectedSeed)
{
// Reset RoomsLoaded to check later
RoomsLoaded = 0;
// Get Data Table that holds rooms information
UDataTable* RoomsTable = Cast<UMainGameInstance>(GetWorld()->GetGameInstance())->RoomsTable;
// Get the names of the Data Tables
TArray<FName> RoomsNames = RoomsTable->GetRowNames();
FRoomInformation* RoomInformation = RoomsTable->FindRow<FRoomInformation>(RoomsNames[0], "");
ULevelStreamingDynamic* RoomLevel;
bool bIsLevelLoadSucessful;
// Create a number of rooms equal to RoomCount
for (uint32 Index = 0; Index < RoomCount; Index++)
{
// Load the level instance
RoomLevel = ULevelStreamingDynamic::LoadLevelInstanceBySoftObjectPtr(GetWorld(), RoomInformation->Level, FTransform(FRotator(0,0,0), FVector(0,0,0), FVector(1,1,1)), bIsLevelLoadSucessful);
// Once LevelStreaming loads properly
if (ensure(bIsLevelLoadSucessful and RoomLevel))
{
// Notify when Level loads properly
RoomLevel->OnLevelLoaded.AddUniqueDynamic(this, &ADungeonManager::HandleRoomLoaded);
// Add to arrays to save for later
StreamedLevels.Emplace(RoomLevel);
}
}
}
void ADungeonManager::HandleRoomLoaded()
{
// A Level has loaded
RoomsLoaded++;
// Did all rooms finish loading?
if (RoomsLoaded == RoomCount)
{
// Get all jigsaws
PlaceRooms();
}
}
void ADungeonManager::PlaceRooms()
{
// Place rooms 1000 units away from each other
for (int Index = 0; Index < StreamedLevels.Num(); Index++)
{
StreamedLevels[Index]->LevelTransform = FTransform(FRotator(0.0f, 0.0f, 0.0f), FVector((Index + 1) * 1000, 0.0f, 0.0f), FVector(1, 1, 1));
}
}