Download

How to spawn runtime's actors in editor

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:


 

  1. TArray<AActor*> actors;
  1. UGameplayStatics::GetAllActorsOfClass(GWorld->GetWorld(), AActor::StaticClass(), actors);
  1. for (AActor* actor : actors)
  1. {
  1. TArray<uint8> data;
  1. FMemoryWriter writer(data, true);
  1. FObjectAndNameAsStringProxyArchive arWriter(writer, false);
  1. actor->Serialize(arWriter);
  1. }

 

At editor end, firstly, I will get the UClass of actor, and then I will use the same method to deserialize data like this:


 

  1. UClass* className = FindObject<UClass>(name);
  1. AActor* restoreActor = GWorld->SpawnActor(className);
  1. FMemoryReader reader(data, true);
  1. FObjectAndNameAsStringProxyArchive arReader(reader, false);
  1. 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?