FObjectAndNameAsStringProxyArchive serializes objects as string references so it won’t pull any data from components.
You can iterate components from the object yourself and serialize them one by one in a similar fashion.
Thanks Chatouille! Is there an efficient way to serialize each component? Will I have to put them into separate archives or can I combine them into one?
You can put them all into one, just make sure to store the amount of them beforehand so you know how many you have to read when loading. Also you might want to store an identifier to identify components as they may not always come out in the same order (using component name maybe, not sure if that’s good enough).
For example (pseudo code) :
// Writing
MyPawn->Serialize(Ar);
TArray<UActorComponent*> Components = MyPawn->GetAllComponents();
int32 Num = Components.Num();
Ar << Num;
for (auto Comp : Components)
{
FString Name = Comp->GetName();
Ar << Name;
Comp->Serialize(Ar);
}
// Reading :
MyPawn->Serialize(Ar);
int32 Num;
Ar << Num;
for (int32 i=0; i<Num; i++)
{
FString Name;
Ar << Name;
UActorComponent* Comp = MyPawn->FindComponentByName(Name);
Comp->Serialize(Ar);
}
This is very barebones obviously and will go very wrong if one of the components is not found, or has changed class.
I can only recommend the standard SaveGame approaches, even if they feel more clunky to implement.