SaveGame: Dynamic ActorComponents

I’m aiming to save and load an actor who has dynamic actor components added at runtime. I haven’t been able to find examples of saving and loading dynamic components.

The actor is saving in my implementation, and it seems to properly save and load static components (eg. it’s static mesh is set properly on load), but I’m having trouble with dynamic components added at runtime - they are not populated on load.

I’m using the SaveGame object method of saving and loading (UGameplayStatics::{Load/Save}GameFromSlot), and the actor is being serialized like this:

FActorRecord record;
record.Name = Actor->GetFName();
record.Class = Actor->GetClass();
record.AttachSocketName = Actor->GetAttachParentSocketName();
record.Transform = Actor->GetTransform();

FMemoryWriter MemoryWriter(record.ActorData, false);
FH2SaveGameArchive Ar(MemoryWriter, false);

At this point, am I supposed to save the components manually? Can I detect if componets were added dynamically? Should I be saving non-dynamic components too?

Any advice or suggestion is appreciated.

EDIT: I forgot to mention that I have been trying to serialize actor components by serializing each component and storing them as an array of “component record” structs, but deserializing them sometimes ends up in an infinite loop while trying to deserialize one of the component’s property tag names (the record is correct, but the component data is failing to deserialize)

1 Like