Save/Load Multiple Structures Issue

I’ll keep this short and simple, how can I create widgets during runtime to add to a grid (ex. 5) all with assigned variables in a structure/data table, and then save+load all of the values? I’ve tried this many different ways, but I feel like there’s a simple way to do it that I’m missing. When adding them to a structure array in the save class, it would either reset to default values or save twice (once on startup then once again when changing the selected item variable) but then never again and would continue to load from that same state. Is that a bug or am I doing this wrong?

Additional notes: When saving/loading variables to separate structures for each widget or arrays for each variable (rather than structure) I have the same issue as the structure array, even after restarting the engine.

I’m assuming your array of structures is part of your save game object, and that you are saving / loading this save game object?

Can you show your code?

Thanks for the details. What troubles me, is that an array of structures is just that, an array of structures, and will work with the save game fine ( as far as I know ).

Your save game system does seem a little complex, even from the text above. Could it be a bug?

To be sure, it might be an idea just to run a basic test with an array of structures, but I’m sure it’s fine.

I’d try writing some ‘dump’ code so you can inspect the state of the save game, and what’s in memory at the drop of a hat, and maybe find out what’s going on.

Try and keep the initial version as simple as possible, I will take a look.

One thing suddenly sprang to mind. You’re not using the async save game write are you?

If so, also switch to the normal version, the async is not good.

Just normal save, here are the images with comments added to help you see what they’re doing. I apologize if the image quality is low, I have a large monitor so I often have people tell me that screenshots get shrunk down terribly.

Inside my save blueprint I added 2 array elements for my 2 data table test rows that should appear (got an error before doing that, and deleted save file and tried again)

The following code saved when I clicked the 2nd button and loaded with that button pressed, but when I clicked the first one and exit/relaunched it loaded with the 2nd one selected once again. There’s something small I’m missing but idk what it is.

Yes, I deleted most of my code in hopes of a good response since it doesn’t work anyways. Give me a few hours to get back in front of my PC then set it up again, and I’ll post screenshots. I’ve done a lot of debugging and unfortunately it’s none of the simple fixes like creating the save game object twice, or not setting the array correctly.

Basically I create the widgets on play based on the number of data table rows, then if not save game exists set default variables to data table defaults. If one does exist (using correct slot name each time) it casts to game instance and loads the structure array, then with another for each loop (widgets of class) it sets the widgets variables using a custom event I made, using the structure at that widgets index (worked with name variable during testing but not all of them

For saving, I get all widgets of class (store icon) then for each loop and get all variables then set the members in the structure array at that particular index to the value of the widgets variables.

That’s basically the code, but can provide screenshots later; however, I don’t think it’s a simple bug with the code, and would prefer if you or anyone knows a better way to save/load multiple structures (with ability to change variables during runtime)

On the load event it loops in the game system then calls a separate event for loading the the widgets form that particular structure, so there’s no issue with it setting the variables to default on play.

Thank you for your responses, and helping me try to fix this, haven’t had much luck on this site in the past so it’s good to finally get help with an issue. I’m getting on my computer and will remake it and send over pictures and hopefully it’s a small issue that I missed.

I’ve tried printing the save structures strings (off of tick) and what’s weird is that they show the correct values then when I print a string after saving it all works no issues (with them showing the correct values), but I quit then open the game and it loads wrong ones. :frowning:

Below is what it displayed, the weird thing is that the name is a part of the structure and does save, restarted engine multiple times also

Example: (“widget name” append “ : “selected bool value”
Output: (“test1 : false”) (“test2 : true”) (“test3 : false”)
Output after relaunching: (“test1 : true”) (“test2 : false”) (“test3 : false”)

Thank you very much! Setting it up now, will only be using the “selected” variable for testing, but all it does is when clicking a button sets the value in the widget you click to true, and then gets all other widgets of that class and sets their values to false (works with no issues). Unfortunately it’s VR so I’m not really sure how I’d be able to send videos of the game itself but will let you know what it does.

Rather than give you a whole essay about this, I’m just going to shoot ideas to you for you to check.

So far I have:

  1. Check this

343415-screenshot-1.jpg

  1. I notice that ‘save hands’ needs the variable ‘hands save ref’, but ‘load hands’ does not set it.

Hey! - excellent :slight_smile:

I changed it to an answer :wink:

Like you said earlier, it’s a simple array, it should store the data then write it, there’s no reason it should do it once, and then never work again and always just save the first saved value it had lol, I’m genuinely confused as to why this doesn’t work lol.

YOU ARE A GENIUS!!! THANK YOU SOO MUCH!! I did both of those things so can’t say for sure which one was the correct fix, but I feel like it was because I wasn’t setting the save ref on load. Works perfectly now, and you just saved me so many hours of coding this many different ways trying to fix it lol, thank you!!!

I guess if you want to type that again or something else as the answer, I’ll mark this as resolved.