I defined a class in C++, and used FObjectAndNameAsStringProxyArchive to save and read the object’s data. There were no problems with the previous 5.0, 5.1, 5.2, and 5.3 upgrades, and I could read the previous data normally. However, after upgrading to 5.4, I could not read the data saved in 5.3.
Here is the demo code
// Class data definition
UCLASS(Blueprintable, BlueprintType)
class UDTObject : public UObject
{
GENERATED_BODY()
public:
UPROPERTY() int m_Int = 0;
};
// 5.3 Save
{
UDTObject * DTObjectW = NewObject<UDTObject>();
DTObjectW->m_Int = 1001;
TArray<uint8> ObjectBytes;
FMemoryWriter MemoryWriter(ObjectBytes, true);
FObjectAndNameAsStringProxyArchive ArchiveObject(MemoryWriter, false);
DTObjectW->Serialize(ArchiveObject);
FFileHelper::SaveArrayToFile( ObjectBytes, TEXT("G:\\Test\\Test53.txt"));
}
// 5.3 Read
{
UDTObject * DTObjectR = NewObject<UDTObject>();
TArray<uint8> ObjectBytes;
FFileHelper::LoadFileToArray( ObjectBytes, TEXT("G:\\Test\\Test53.txt"));
FMemoryReader MemoryReader(ObjectBytes, true);
FObjectAndNameAsStringProxyArchive Archive(MemoryReader, true);
DTObjectR->Serialize(Archive);
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString( FString::FromInt(DTObjectR->m_Int) ));
// out DTObjectR->m_Int == 1001;
}
This can be saved and read normally, and I can also read the data saved by 5.2.
// 5.4 Read
{
UDTObject * DTObjectR = NewObject<UDTObject>();
TArray<uint8> ObjectBytes;
FFileHelper::LoadFileToArray( ObjectBytes, TEXT("G:\\Test\\Test53.txt"));
FMemoryReader MemoryReader(ObjectBytes, true);
FObjectAndNameAsStringProxyArchive Archive(MemoryReader, true);
DTObjectR->Serialize(Archive);
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString( FString::FromInt(DTObjectR->m_Int) ));
// out DTObjectR->m_Int == 0; !!!!! Restore failed
}
I used the same code in 5.4, but the class data could not be restored. I used to be able to use it when I upgraded from 5.2 to 5.3.
Then I checked the uint8 saved in 5.3 and 5.4, and the two memories were completely different. Could it be that 5.4 was updated and incompatible with the previous ones?
Is there any conversion function? Otherwise, the custom archives I wrote before cannot be read after upgrading to 5.4.