Maybe? I think there are a lot of details that make thing work or not that are hard to discuss in the abstract.
I wish I had a version in my github to share, the only versions I’ve written are in company depots. It’s on my list of things to write & share if only as an example. But at a high level:
- A component that acts as an identifier that the owning actor state should be saved. This has an FGUID as the unique ID. When that component is saved in the Editor, it copies the value from the ActorGuid and sets a flag that indicates that this is a level actor. Otherwise the GUID is generated lazily for spawned objects.
- Saving consists of finding all the actors with the persistence component and serializing them into a byte stream. This is done with a custom FArchive. FArchive has a few overload-able functions for dealing with different sorts of object references. I overload those to handle the serialization of the reference.
- First I gather the collection of objects that should be saved. This starts with all the Actors with the Persistence component, but is expanded to objects that they reference. I have a list (in developer settings) for the component types that should be saved (since you don’t really need to save mesh or collision components).
- As I serialize each object, the overloads gets called for object reference members. If the object being referenced is in the “to-save” collection, I serialize out that index value. If that object is a persistent object not in the list (for reasons not worth discussing now), the GUID is saved. If that object is not-persistent but is a or in an asset, save the object path. Otherwise error/ensure because there’s no good way to persist the reference. (I don’t currently support subobjects of persistent objects but that is a case that could be handled)
- When loading, I create all of the object instances from the save data. Then serialize each object. This way when the overloads de-serialize the object reference I can fill it in with the constructed object (if it was in the list), an existing persistent object or the asset object (maybe with a sync load on the soft path).