My array saving doesn't work

for anyone curious, this is a comparison the what some of the objects looks like while i save them, and what they look like after i load them (it cuts to the loaded footage when the screen goes black)

There’s no mystery here. You’re getting the actor references jumbled up, either on saving or reloading.

Also, here

You’re apparently using a structure, but then just using Add to talk to an array of transforms, that could be in ANY order :slight_smile:

The most logical way to keep everything where it belongs, is a map.

image

Then, things don’t get lost.

Assuming you manage the save game correctly ( not shown here ), this is all the code you need

I just used this on all the meshes in the first person example map. It works flawlessly.

That’s 53 meshes.

And I restore them ( for instance ) without rotation. And then with rotation

save and load

As clockwork says, you have some nodes not quite setup right per how I was trying to write it, sorry I didn’t provide any images.

His examples should be all you need.

He is using a Map, but if you want to save more then just Transforms, a Struct does work just fine as well.

Edit:
Here’s what I was trying to explain, using Structs…

Struct is setup like this, add more variables if you want to save more attributes

Save Game Object has an Array of the Struct, each item of the Array contains all the data for 1 actor you are saving, keeping everything together.

In a Save Game Function, I like to use Local Variable to Prepare the data, especially with large save systems with tons of data, then set my Save Game Object at the very end, once all my data is prepared, then save that to a Slot.

Local Variables don’t need to be cleared first, as they already are by default.

1 Like

alright, i tried it, these are what my save and loading functions look like now



it didn’t work, the objects aren’t getting weird sizes, their values are all just the same ones that they have originally set in the level, but the static meshes are still invisible when the game is loaded as well (btw i did check the results of the transforms with the “print string” nodes) so if you noticed anything wrong, let me know. Also, are your save and load functions made in your level blueprint? Cause maybe your save and load functions only operate correctly on them, for some reason.

OH MY GOD, i just figured it out, i can’t believe the answer was so close in front of my eyes. The problem was that all my actors were set to static. I always updated their locations with animations, so setting their locations was never gonna work. It works now, i don’t know why my box brushes disappear, but that’s for another problem

2 Likes

No, this was an actor that I dropped in the level.

okay, although things are working now, it only works if i get into the level directly from the “play” button in unreal engine. If i load the level from the main menu, the player location loads correctly, while the object locations are reset to default. Any idea why that might be happening?

I’m starting to wonder if all your problems are coming down to the sequencer.

I must say, it’s a bit of a strange way to make the transforms.

Blueprints would fit better :slight_smile:

wdym by “the sequencer” exactly… yeah i am fairly new to unreal engine, hah

You said it :slight_smile:

This sounds like a timing issue tbh.
Check that the objects are valid within your load save script, put some print strings for “Valid” / “Not Valid”, start your game and see what gets printed.

If you see “Not Valid”, the Load script is running before the objects are in the scene, figure a way to delay your load script, or call the save game data upon object load (if these are Blueprint actors, you can do it at Begin Play). If these are Meshes, you will need to confirm they are valid before the Loading continues.

oh, yeah. I just move things around the map by animations, cause that seems easier

so the player location works fine, the array saves data seems to reset with any use of the “open level” node overall, idk what causes that, but hopefully it isn’t that hard to fix, perhaps some of you already recognize what the issue here is, if so - tell me

But how does the sequencer know which asset its updating?

Open level flushes everything. If you haven’t written to the save game, everything will be lost.

but doesn’t the save function already do that? Also, it clearly doesn’t lose everything, because my player location still saves. Is that supposed to happen?

See the question about the sequencer, above…

oh wait actually nevermind, i think the problem was actually with the game instance, i tried doing the same code in the level blueprint and it’s actually works flawlessly now. It’s probably not the most correct way to do it, but the fact that it works is all i need. I’m just glad to be done with all of these finally

1 Like