How Do I Efficently Save Lots Of Actors

Hey guys, so I want to refactor my save/load system to be a bit more optimized. I have creature and structure actors right now that I want to save. These both have unique id’s assigned to each instance. My current method of saving them is by creating a new file for each actor. These files contain the actor transform, class, and a TArray that holds all the serialized data and these 3 properties are placed inside a struct. For saving all into a single file, should I add an ID property to the struct and save a file containing an array of the structs? And then for loading, would I go through each struct inside the file and spawn the actor and if the actor is out of range of the player, I disable the renderer or something to improve performance? And for saving individual actors when I need to, would I just get the array of structs from the file and loop through it and search for the id, if it exists, overwrite that struct, if it doesn’t exist, just add a new struct. I can provide more info if needed. Thanks in advance!

Hello! First of all, how often are you going to Save your data to file or Load from it? If your answer is very often, maybe it would be better to use fast memory cache instead of slow read/write from disk. It can be helpfull for restoring data in levels during one player session (go to level1 then to level 2 and after that again in level1). With memory cache, the question of saving one actor become trivial.

Hi, I am not going to be saving super often. The player is going to be saved most often, every 30 seconds. And all of the other creatures/structures are going to be saved every every couple of minutes.This is probably where the biggest performance hit will come so I’m thinking about having each object be in charge of saving itself at significant moments instead of every x minutes. As for loading, everything is loaded on initialize but after that, there isn’t any loading. And using memory caches seems interesting, are there any good sources I could look at for using them?

Hi! Simple approach is to use TMap(id, FBufferArchive) and add/update data by id of actors with universal byte format for data itself. To decrease number of object saving in one moment of time some people use random time delay to dsitribute all of them along interval. So this memory cache of TMap can be updated often and with lower rate - to disk.