Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Serialize Game

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;
 FWorldContext& wc = GEngine->CreateNewWorldContext(EWorldType::Game);
 FFullyLoadedPackagesInfo fullyLoad;
 fullyLoad.FullyLoadType = EFullyLoadPackageType::FULLYLOAD_Map;
 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;
Product Version: UE 4.11
more ▼

asked Jun 05 '16 at 05:08 PM in C++ Programming

avatar image

168 11 17 31

avatar image Jerry.Richards Jun 05 '16 at 09:49 PM

I may be getting a little closer. Sometimes I am able to serialize 6 levels worth of data before it crashes, other times, I only get a few. Here's what I have thus (which is contained within a loop over the levels):

 UWorld* world = UWorld::CreateWorld(EWorldType::Game, true);
 FWorldContext& wc = GEngine->CreateNewWorldContext(EWorldType::Game);
 wc.OwningGameInstance = gameInstance;
 //APlayerController* pc = wc.World()->SpawnActor<APlayerController>(APlayerController::StaticClass());
 UPendingNetGame* pending = nullptr;
 FString Error;
 if (GEngine->LoadMap(wc, *level->LevelPath.ToString(), pending, Error))
     // the below causes an error which is something I wouldn't expect to
     //AMyGameMode* gameMode = (AMyGameMode*)UGameplayStatics::GetGameMode(world);
     //*outFile << *gameMode;
     // getting the World Settings, then getting the game mode is a workaround
     TArray<AActor*> WorldSettings;
     UGameplayStatics::GetAllActorsOfClass(wc.World(), AWorldSettings::StaticClass(), WorldSettings);
     if (WorldSettings.Num() > 0)
         AWorldSettings* worldSettings = Cast<AWorldSettings>(WorldSettings[0]);
         AMyGameMode* gameMode = (AMyGameMode*)worldSettings->DefaultGameMode.GetDefaultObject();
         *outFile << *gameMode;
     TArray<AActor*> Managers;
     UGameplayStatics::GetAllActorsOfClass(wc.World(), AMyManager::StaticClass(), Managers);
     if (Managers.Num() > 0)
         AMyManager* manager = Cast<AMyManager>(Managers[0]);
         *outFile << *manager;
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question