I’m attempting to serialize some additional data with an asset. I assumed I’d be able to override UObject::Serialize
and read/write to the archive, but I hit an error at the end of FLinkerLoad::Preload
when I do this.
UE_LOG(LogLinker, Fatal, TEXT("%s"), *FString::Printf( TEXT("%s: Serial size mismatch: Got %d, Expected %d"), *Object->GetFullName(), (int32)SizeSerialized, Export.SerialSize ) );
I’ve been searching around, but I can’t find any documentation on custom serialization. The few places I can find in the engine that override Serialize
seem to do the same thing I’m doing. Can someone point me in the right direction?
UCLASS()
class UEntityDefinition : public UDataTreeAsset /* Custom asset type */
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
int Value;
virtual void Serialize(FArchive& Ar) override
{
Super::Serialize(Ar);
int32 Foo = 32;
Ar << Foo;
}
};
Your usage looks correct, but you must already have one of these objects serialized in a package. The editor tries to load the asset, but crashes because it was saved WITHOUT the additional data, and now you try to load it WITH the additional data.
If you look into UE4 source code, you can see in various places they handle this with versioning, like :

I’m making a brand new asset. There are no preexisting assets of this type. I’ve been deleting them and recreating them for each test, just to minimize variables.
The error is actually because more data is deserialized than expected. By exactly the amount that I’m adding.
/Game/EntityDefinitions/A.A: Serial size mismatch: Got 16, Expected 12
Are there rules about adding serialized data if there are already serialized properties? It seems like the UObject::Serialize implementation is recording how much it serializes to an ExportMap and checking against that later. That doesn’t seem to include the size from any data I add, whether it’s before calling the super implementation or after.
Turns out that overriding the FRecord overload is what causes the error.
Here’s a complete example that will raise a fatal error after creating, saving, and reloading a new data asset.
#pragma once
#include "Engine/DataAsset.h"
#include "StubEntityDefinition.generated.h"
UCLASS()
class UEntityDefinition : public UDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
int Value;
virtual void Serialize(FArchive& Ar) override
{
Super::Serialize(Ar);
int32 Foo = 32;
Ar << Foo;
}
// If this is enabled it causes a fatal error when appending additional data in the Serialize
// overload above
virtual void Serialize(FStructuredArchive::FRecord Record) override
{
Super::Serialize(Record);
}
};