How to deserialize a TSubClassOf<>?

Is there a way to deserialize a TSubclassOf<>? When I do it the result is a nullptr

TArray<uint8> ByteData;


// Write
{
    TSubclassOf<AEquipmentBase> Equipment = ARifleWeapon::StaticClass();
    FMemoryWriter MemWriter(ByteData);
    FObjectAndNameAsStringProxyArchive Ar(MemWriter, true);
    Equipment->Serialize(Ar);
    // ByteData seems to hold a value.
}


// Read
{
    TSubclassOf<AEquipmentBase> Restored;
    FMemoryReader ComponentMemReader(ByteData);
    FObjectAndNameAsStringProxyArchive ComponentAr(ComponentMemReader, true);
    
    ComponentAr << Restored;
    // Restored is still nullptr
}

Read and write both with the << operator instead of using Serialize in one and << in the other.

// Write
Ar << Equipment;

// Read
ComponentAr << Restored;
1 Like