What is the best way to handle Saving/Loading an Array of Objects?
I've looked at tutorials, Tappy Chicken and Rama's example, but can someone tell me what is the "recommended" way to save and load an array of objects?
More specifically, procedurally generated actors, which seem to break the FArchive derived routines in the engine (they use FindObject, but since they are procedurally generated, they are not assets). I can code up something custom, but I was wondering if I missed something built-in that would do the transforms, materials, etc.
The << Operator
"something built-in that would do the transforms, materials, etc."
Check out ArchiveBase and Archive.h
If you have a UE4 type, try using the << operator on it!
Transforms, Materials, Etc should all be covered by the << operator already.
Then for your class you define your own use of the << operator, which uses the existing UE4 type << usage
Here's an example:
Spawn and Load
Final step when loading is to spawn fresh copy of class and then use the << operator on it! (or fresh struct)
There is currently no good tutorial on how to do a custom save game setup for your game, so it will require a good bit of custom coding on your part. But here's some info that may help out:
For fortnite, we're using a system built on the SaveGame property flag. If you set the ArIsSaveGame archive flag on an archiver, it will only serialize properties that have that flag set on them. Some of the basic properties are set this way in the engine, and you can then tag your game specific properties.
So, you need to set up a savegame archive. For fortnite, we're using a proxy wrapper based on the Objects-as-strings proxy wrapper:
Then, you can use that proxy archive to serialize a record for an actor or object you wish to. Here's our save code, that writes to a simple struct that has the actor's class, transform, and a TArray storing the bytestream:
And here's our code that restores that actor:
So we're using this system for Fortnite, which has a complicated system of procedural generation. Basically there's a state machine that handles either generating the actors randonly, or restoring from a record like above. We also use a similar technique to save a player's inventory, but instead of saving a whole actor we just serialize a specific Struct, which is a great place to put your array of objects:
answered Jul 01 '14 at 01:06 AM
[Epic]Ben Zeigler STAFF
Hi Guys, I was struggling with this for a bit and still learning best way to do it. I've create a wiki page showing what i've setup so far if it might help with your setup in anyway, posting here because this is one of the most complete answers and most helpful for me so just thought I could add to it if it helps anyone else:
Feel free to offer any suggestions to update the page or clarify anything if you want :)
answered Oct 19 '17 at 11:09 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here