I’ve already tried with Rama’s method of ULevelStreaming it but the flickering would not disappear without doing some hacky stuff, so I’m now loading the packages myself and using AddToWorld(ULevel*, FTransform) to do the dirty job. It is apparently working in the editor, but once you press simulate, everything disappears.
This is my code and I was wondering whats wrong with it:
void ABoard::LoadLevel(int32 X, int32 Y,const FString &File) {
UWorld* World = GetWorld();
FTransform Position(FVector(1000.f * X, 1000.f * Y, 0.f));
UPackage* Package = (UPackage*)StaticFindObjectFast(UPackage::StaticClass(), NULL, *File, false, false, RF_PendingKill);
if (!Package) Package = LoadPackage(NULL, *File, LOAD_None);
if (!Package) return GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, TEXT("Package Not Found: ") + File);
UWorld* PackageWorld = UWorld::FindWorldInPackage(Package);
if (!PackageWorld) return GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, "No World in Package?");
ULevel* Level = Cast<ULevel>(StaticDuplicateObject(PackageWorld->PersistentLevel, PackageWorld, *FString::Printf(TEXT("TILE_X%d_Y%d"), X, Y)));
Level->bGeometryDirtyForLighting = true;
Level->bRequireFullVisibilityToRender = true;
World->AddToWorld(Level, Position);
}
EDIT
I’ve been struggling with this for a while now, I’ve found that the Level gets loaded and added to the UWorld, but for some reason it’s not showing. I think I need to do something else to activate them, but I have no clue.