I’m currently working on setting up save/load logic for my project, and have run into a problem that’s left me a bit perplexed.
To save data, I need to package data about objects into UStructs. I’m trying to build a UStruct (FObjectSaveData) which can generically handle common data. To do this, I have a TMap for each common data type. The idea is that basic objects will implement a function which returns an FObjectSaveData which contains the data that object needs to save, with the index of the TMap being the name of the UProperty which the object saved. Some objects will have custom handling, but for the most basic objects, I’d like to have a generic system which just links data to UProperties.
The problem, is that often objects have subobjects. Actors having components, scenecomponents having children, etc. So I also want to have a TMap of further FObjectSaveDatas, so the save data structure for an object mirrors the setup of the object.
Now, normally, you can’t have a struct contain an instance of itself, since that would cause infinite nested structs, so this wouldn’t be a problem. But in this case, since the struct is within a TMap, which by default is empty, it should be okay.
The issue is I can’t figure out how to declare the UStruct in such a way that the compiler already has a definition for the FObjectSaveData struct when it tries to compile the full FObjectSaveData. I can’t forward-declare the struct, since it’s not a pointer that’s being used in the TMap. While UStructs are …sort of… objects, UProperties don’t like pointers to structs, so I don’t think I can just make the TMap contain pointers to the structs. Also, I don’t think the Save system would be able to deal with that since presumably, it’d just literally save the memory address of where the UStruct used to be, which is useless after a load.
What’s the best way to handle this? UStructs are stuck in the weird twilight between being proper objects and regular old structs, and TMaps/Arrays do their own things when it comes to the save system, so I’m not sure what I can do with them in this case.