Set Array Elem or Add?

Hey,

I’ve been looking through a lot of save systems, and most marketplace assets use “Set Array Elem” instead of the “Add” to array node for saving array structures.

Up until now I have used the “Add” node, but I was wondering if it was better to use the “Set Array Elem” node instead? Does it increase loading time/performance. Or what benefits does it have compared to the “Add” node? I’m trying to hunt down some issues where loading crashes or makes the game lag, but even disconnecting every load event, packaging the game and testing if it worked, didn’t work. All the save data is still there even if I overwrite the save and reload the save.

Most of my saving code at the moment is clearing the struct → get all actors of class → run array through a for each loop → via Loop Body I use the Add node to make the struct and add it to the saved array. Below is an example of my loading codes for every actor I try to load:

I have also run into some issues where a lot of the time, where if I for example save an actor class to the array, then I change the actor in the engine, and try to play again, it keeps the old version of the actor before I changed it in the save. How do other developers go about this?

EDIT:

The issue with old versions of actors being saved was resolved when disconnecting the pin between “Get class” and “Spawn Actor of Class”

This is intentional. You saved the old version, so it can only load the old version. You’ll have to save the new version.

I can definitely see me misinterpreting what you’re trying to ask here, so feel free to ask for clarification- though please provide your own clarification along with it.




Add vs Set element really just comes down to situation and coding style. If you don’t obviously need a set element node, then you likely don’t need a set element node.

Like in your example- you could reverse the for loop and use a set array element node with size to fit checked- but while it will reduce the number of times you have to resize the array, there’s not enough reason to add that much complexity when an add node works fine. Unless you’re saving hundreds of thousands of these log racks, you don’t need that optimization.

Hey,

Thanks for quick reply! I think I understand the set array elem or add part better now so thank you for that.

I think you understood me though with the first part. But just incase, I can clarify a bit more: The issue I mean, is that I have an old save, from several patches ago. Then in the recent patch, I have adjusted that actor inside of unreal engine. And when I try to load up the old save from patches ago, also after patching the game via steam, I go to test if the new one is there, and its not. The old version is there.

So by saying I have to save the new one, how would I go about doing that? Is there a way to overwrite the old version, even though they are the same blueprint? By that I mean, I didn’t create a new blueprint and added that to the patch. I just edited the old one.

I am guessing it has something to do with me using “get class” from the for each loop and plugging that into the “spawn actor” class?

I’m not sure I understand what you are changing. You’re saying you’ve “adjusted” it, but I’m not sure what that means.


[As an example] You have a red-colored barrel and create a save. You then change the color of the barrel to blue. You then question why the barrel is still red in your old save.

In this example, new saves would have blue barrels and old saves would have blue barrels.

If this is an accurate example, it’ll be because you save the color of the barrel somewhere. If you want to change the color to blue in the newer version, you’ll have to create a function that, when loading a save of an earlier version, changes the color to blue manually.

Hey, sorry for not being clear enough. Your example is what I mean though by adjusting the BP.

I’ll test around with the saved class and see if just disconnecting the “get class” pin from the “spawn actor” and setting the class directly in the “spawn actor” will do the trick.

Thanks for the help! I’ll edit the original post if that was the case and set your comment to the solution!