Announcement

Collapse
No announcement yet.

Serialization all level

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [PROGRAMMING] Serialization all level

    Hi! I want to add save/load system in my game.

    I wrote code C++ serialization. Saving to file is correct. But loading and setting parameters in actor is not work.

    It is my code.
    Code:
    // Save
    void ASaveSystem::SaveAll_Implementation(AActor* Object)
    {
        if (GEngine)
            GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("Save"));
    
        TArray<uint8> ObjectData;
    
        FMemoryWriter MemoryWriter(ObjectData, true);
        FObjectAndNameAsStringProxyArchive Ar(MemoryWriter, false);
        //Ar.ArIsSaveGame = true; //Set achive is savegame
        Ar.ArNoDelta = true;
        Object->Serialize(Ar);
    
        FString SavePath = FPaths::GameSavedDir() + FString("SaveGames/") + "mysavefile.save";
        FFileHelper::SaveArrayToFile(ObjectData, *SavePath);
    
    
    }
    
    // Load
    void ASaveSystem::LoadAll_Implementation(AActor* Object)
    {
        if (GEngine)
            GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, TEXT("Load"));
    
        TArray<uint8> ObjectData;
    
        FString SavePath = FPaths::GameSavedDir() + FString("SaveGames/") + "mysavefile.save";
        FFileHelper::LoadFileToArray(ObjectData, *SavePath);
    
        FMemoryReader MemoryReader(ObjectData, true);
        FObjectAndNameAsStringProxyArchive Ar(MemoryReader, false);
        //Ar.ArIsSaveGame = true; //Set achive is savegame
        Ar.ArNoDelta = true;
        Object->Serialize(Ar);
    
    }
    What happend? Please people, help me.
Working...
X