Moving it here so there’s more space for the chunky screenshots and I don’t get logged out all the effing time
Let’s say I saved multiple actors from
the level into an array. Then I quit
the game and load the array. How would
I tell Unreal which element belongs to
which actor?
I would not use the Display Name
for this. You could use a [Map][1] (a.k.a. Dictionary) to identify actors efficiently. Think of the Map as if it was a Data Table but you do not get to use a snazzy interface. It’s a list of uniquely named things. There is a Key
& and a Value
associated with that key.
The one on the left is Name | Actor - it keeps a list of actors to find; the one on the right is Name | Struct - that’s the one we’re going to save and load.
I have those 2 boyos in the level:
They each have a data struct, one of the variables is their Unique Name. And Roger Says Hello.
When I’m ready to save:
- grab all actors that need saving and put them in the Map variable, using their Unique Names as keys: the
CreateActorsMap
Event - first I modify what Roger has to say so there’s something to save
- create a save game object
- step through the Name | Actors map, read actors’ structs and push them into the save game’s Name | Struct map
- save to slot
When I’m ready to load the map and restore any saved actors from this level:
- once the map has been loaded
- create the a Name | Actor map of existing actors in this level, using the same method as before
- load the save game object, step through the Name | Struct map
- use the unique name to match an actor in the level
- if the entry does not exist, this actor was not a part of the level, it needs to respawned from scratch and then given the struct
And while you can do a similar thing with an array, with the Map you get to choose by name. If you need to find a particular actor (5 of 5000) and only update those, you can; rather than loop-break through a 5000 element long array and compare names.