Hello All.
I’m trying to serialize parts of my game, which is spread over several levels and game modes. I need to load each level, interrogate which objects are in the scene, and serialize them as needed. Unfortunately I cannot get the levels to load into the world correctly. I’m not certain of the order of operations below either, in particular the GEngine->WorldAdded() part, but also the general setup and loading of the levels. After the UGameplayStatics::OpenLevel call the world appears to be empty.
Can anyone offer any guidance on this?
Thank you.
UWorld* world = NewObject<UWorld>();
UWorld::InitializationValues initValues;
initValues.AllowAudioPlayback(true);
initValues.CreateAISystem(true);
initValues.CreateFXSystem(true);
initValues.CreateNavigation(true);
initValues.CreatePhysicsScene(true);
initValues.InitializeScenes(true);
world->InitializeNewWorld(initValues);
GEngine->WorldAdded(world);
FWorldContext& wc = GEngine->CreateNewWorldContext(EWorldType::Game);
wc.SetCurrentWorld(world);
FFullyLoadedPackagesInfo fullyLoad;
fullyLoad.FullyLoadType = EFullyLoadPackageType::FULLYLOAD_Map;
fullyLoad.PackagesToLoad.Add(level->LevelPath);
wc.PackagesToFullyLoad.Add(fullyLoad);
UGameplayStatics::OpenLevel(world, level->LevelPath, true);
TArray<AActor*> Managers;
UGameplayStatics::GetAllActorsOfClass(world, AMyManager::StaticClass(), Managers);
if (Managers.Num() > 0)
{
AMyManager* manager = Cast<AMyManager>(Managers[0]);
*outFile << *manager;
}