My array saving doesn't work

I’ve been struggling with array saves forever now. I’m mainly trying to save the locations and rotations of different actors around my level, cause it’s very interactive with actors switching their locations a lot. I’ve made a checkpoint system, player transform saves and loads perfectly fine, but there’s my actors are behaving very weirdly. As soon as it loads all my save data for arrays, some objects (and it seems to be a random selection of objects, since some are affected with no real meaningful differences between them) are set to the default size for actors (1,0; 1,0; 1,0) and some are both set to their default sizes PLUS get sent to default locations. The overall summary, and thing in common about this though - the actors aren’t being set to the transform details they were saved with. Here’s a screenshot of the event graph


this is what my Save Data function looks like

and here’s my Load Data function

If you notice something incorrect in any of these images of my game instance, which is the main save function for my game (feel free to ask me about other details you might need information about)

I’d put a print string here, to see if the actors are what you expect them to be.

image

One thing I’m wondering, if they are even in the same order.

The other, is can you even save objects to the save game…

I would try replacing the Add nodes completely.
Make some local Arrays based on how you want to save, ideally create a Struct or Map to keep Transforms and Objects together, then after all your data is organized, Set the Save Game Object, completely setting the Arrays & any other variables within the Save Game Object in 1 shot, then pass that to your Slot

okay, i’ve added a print string to there, and it is being printed when the game loads, that’s what was supposed to happen, right? So it seems the object transforms are in fact being loaded

Sorry, I meant like this

image

so you can see the object names coming back out. Is it as you expected?

Also, as @David_Studio46 says, it might be a good idea to use a map ( object ref → transform ). Then you know they’re not getting jumbled up.

oh, haha. Yeah i suspected it would be something like that, i just didn’t know that was how to do it.
So i tried it out, it seems it’s affecting all the objects it’s supposed to (as in it’s affecting the objects with the tag i set it to target) i later switched to see what the transform values of each object is. I compared the values it saves with the ones the game loads. It seems the loading is the most likely source of the issue, because the values are all correct when they get saved, and only get messed up once the game loads them. Also, it seems there is actually pattern when it comes to what objects are affected in what way. Objects that were built into the engine (such as basic cubes, spheres, trigger boxes) get default values when loaded (0 on every coordinate, 0 on the roll, pitch and yaw, 1,0; 1,0; 1,0 set on the scale) Imported models are a bit less problematic, cause they don’t get default values for the most part, but instead their values that load are ones they have originally set to them in the level, everything besides the scale that is. Scale is reset to default like it is with the objects that are built into ue5. It’s all really odd to me, but with a bigger picture of what’s actually happening, and knowing that the problems are caused with the loading, maybe we’ll eventually get somewhere, perhaps you know what causes all of this

Well, I wouldn’t try and do it that way.

Just start with the level, as is.

If the player changes something, destroy the original actor, replace it, and record the class and transform of the replacement.

When the level re-loads, apply your saved info by destroying the actors and replacing them with the correct class, which you transform.

It gets much easier, if you replace all the meshes with blueprints, that look like meshes, but can record what you do to them. Then, on reload, each blueprint just transforms itself.

but wouldn’t that mean each actor that could be moved in game needs their location set manually? Idk, I guess I could try that out, but the fact that i still don’t know why this is happening is getting me curious, did you even notice a problem with my loading function? Is it just behaving weirdly even if the code is correct. As many potential ways around the situation there are, i also wanna know what i’m doing wrong, that’s getting my saving to not work, compared to plenty of other people who’s codes seem to work just fine. Does the loading function look correct to you, or is there a different way you’d make it?

I can’t see anything specifically wrong with your code, apart from storing object references which, if you take a look on these forums, does often lead to problems.

Can you outline what the game is like? Some pictures etc. What happens?

Maybe I can see something useful.

PS: Strangely enough, I have coded up something similar, and it seems to work fine. But I wouldn’t use object references in a packaged game. I really don’t know if that would work.

Ah… are you clearing these first?

image

I would avoid storing an object ref, use an ID of some sort, an int, a tag, something. Because you might be running into a situation where the loading is happening before the object is in the world.

I would setup the objects to look at the save data on begin play (which is where the ID you choose comes into play) and transform themselves, this way it avoids any timing conflicts.

Doing it your way, you will need to ensure the objects are loaded first, you can add some checks, delays, or something before running the load commands.

what exactly do you mean by that? I know it may sound extremely stupid for me to ask, sorry about that

well the delays didn’t work, which makes things a bit clearer, the transform values aren’t ruined when they’re loaded into the game, they’re already incorrect if i try and get the values

so it seems the most likely problem is what you’re describing, the fact that i’m storing object references. Do you happen to mean it’s bad that i’m storing the transform values the way i am or it’s bad that i’m storing the object references. Anyway, how else can i do it? What else would work besides object references? The answer might need a lot of in depth explanation of how i’d need to change stuff around, so if you know any in depth explanations (maybe a tutorial on youtube, or some other unreal engine forum solve of a similar issue to this) send the links here, or maybe the explanation is pretty easy to explain, and you can just tell me here. Anything that can work out tho, and make the code work more properly, do let me know

Are you emptying the arrays each time? ( otherwise you’re just collecting rubbish with that add node… )

no i don’t think so. I’ve messed around with the blueprint and it’s still giving the incorrect values, but not entirely default this time. Idk everything just doesn’t make sense, so i think you were really onto to something when you said object references seem to be problematic for a lot of other people. So obviously there should be some other way to do it

I just looked at my save game system, and I am also storing Object references for some of my objectives. For me, these are actors permanently present in the world. I think it’s more problematic if you are saving created/spawned actors.

I looked more closely at your images and another thing I don’t like is the “Save Game to Slot” is within your For Loop. This seems problematic in theory. This node is serializing your data onto the player’s Hard Drive, so it seems possible the serialization process doesn’t play nice with the For Loop.

Ideally prepare the save data first then Save to Slot one time, at Completion of the For Loop for example.


I still don’t like the Add nodes they way you have them, data can get out of sync easily.

You can create Structs to hold sets of data.

I have a devlog from a couple months ago that explains some of my Save System for my current game, all in Blueprints, starting at 8:18. It’s not a tutorial so I don’t show absolutely everything, but maybe it helps: Majestic Devlog 6


Disclaimer: I’m not an expert :slight_smile:

This is what I would try.

1.) Create New Structure → Create 2 Variables: Actor and Transform in the struct.

2.) Add New Variable to Save Game Object → Variable type is your new Struct → Make it an Array

3.) In your Save Game Function → Add Local Variable → Type is your new Struct → Make it an Array

4.) In your Save Game For Loop, populate this Local Variable with Objects + Transforms

5.) On Completion of For Loop → Set Save Game Object → Make Variable in Object = Local Variable

6.) Save to Slot node after that

Test it - create print strings in your For Loops, for saving & loading, make sure the data is what you expect. If final actor is still not in its desired state, it must be a conflict at the end of the chain, the actor itself doing something after loading, or a timing issue where load happens before actor isn’t in the world yet.

With this method, the data stays together and you can even modify the Struct if you want to save more information for the actor.
Create additional structs for different types of assets you want to save.
For example, In my game I have 1 struct for the player character, 1 for my day/night system and 1 for primary objectives.

Yes, use blueprints and IDs… :slight_smile:

alright, a small update, after collecting data (that’s with the fact that the load system works slightly differently, since i’ve been experimenting) it seems the first time the game loads the wrong locations, and the next time, the transform values are the way they’re set originally in the map, which means that the checkpoints don’t do much since i want them to load the UPDATED transform values. By the way, i change the actor locations by level sequences. Anyways, i’ll be sure to try out the things you all suggested

about the structures and the “completed” part of the “for each loop” node, i tried out with both those things, here’s how i updated the saving system


unfortunately those still didn’t seem to work. Also, there’s a another weird thing about the saves. They seem to destroy or make box brushes invisible, so maybe you know some info on that. For now, i’ll be trying out the 6 steps you listed, while i’m trying that up, be sure to keep me updated if you’ve found out anything else that might be useful