I wanna build a tool about get all actors in level and serialize them. Next I will send serialized data through socket to editor to spawn the same actor of them in editor.
However, at runtime game end, I use method like this:
TArray<AActor*> actors;
UGameplayStatics::GetAllActorsOfClass(GWorld->GetWorld(), AActor::StaticClass(), actors);
for (AActor* actor : actors)
{
TArray<uint8> data;
FMemoryWriter writer(data, true);
FObjectAndNameAsStringProxyArchive arWriter(writer, false);
actor->Serialize(arWriter);
}
First, I will get the UClass of actor, and then I will use the same method to deserialize data like this:
UClass* className = FindObject<UClass>(name);
AActor* restoreActor = GWorld->SpawnActor(className);
FMemoryReader reader(data, true);
FObjectAndNameAsStringProxyArchive arReader(reader, false);
restoreActor->Serialize(arReader);
When I send serialized data to my editor, I spawn actors with serialized data, I only get actors without any information.
And this is information about one StaticMeshActor object’s serialized data:
StaticMeshComponentObjectPropertyws/Game/FirstPersonCPP/Maps/FirstPersonExampleMap.FirstPersonExampleMap:PersistentLevel.BigWall.StaticMeshComponent0RootComponentObjectPropertyws/Game/FirstPersonCPP/Maps/FirstPersonExampleMap.FirstPersonExampleMap:PersistentLevel.BigWall.StaticMeshComponent0ActorLabelStrPropertyBigWallFolderPath
NamePropertyArenaGeometry/ArenaNone
So my problem is how to get whole actor’s information, including component, transform, material and so on. Next is How can I use the information to spawn the same actor in editor, just like opposite flow of serialization?