Compare and update before and after Save & Load

Hi all,

I’m having trouble implementing my “logic” of how to do this:

When you start to play, you have a layout, but nothing in it, and you can populate the layout with different things (Actors), rotate them, move them and you can also delete them. You can “Save” at any point, and “Load” at any point. When you save, it would compare every object (that can o should be monitored to be saved) to the array variable (maybe a Struct array with Actor, Class and Transform). Then it would update that array, removing the Deleted actors, updating transform data from other actors (if applicable), and after updating the array, saving the slot. once you load, it can do the same thing, or (and I think this is better for resources, correct me if I’m wrong, please) it would just get a clean slate, and spawn everything as it is on the Save Slot Array Variable.

So:

Save → Call all actors from (tag, Instance, Class, etc) → Compare with array variable → update array (changes, or differences) → Save Slot with Updated Variable
Load → Clear level → Call Variable from Save Slot → Spawn actos from Variable → Update Array Variable

Please! if anyone can help me with this, I’ve beet at it for way too long, and I can’t figure out a way of doing it… I’ve only gotten as far as saving the Struct (with Actor, Class and Transform) of each actor in a Struct Array the moment you spawn them, and then when click on Save, it copies that variable with the info into the Instance, and on load it calls that variable from the instance, copies it into the one updated when spawning actors, and spawning every actor in it… When I tried removing from the array, every “click” it only removes Half of the array (so if I have an array with eight, I press Load and Removes 4, then 2, then 1, then all of them. that if they where deleted in the first place, its just weird) And when I save, I’m not comparing anything with the array, so I can still spawn everything multiple times one on top of the other…

I literally need what I described above, I feel the logic is pretty optimized for not consuming a lot of resources, I just don’t have the experience and/or knowledge yet to implement it on my own.

Any help is greatly appreciated!!
Thank you in Advance

Best Regards!

NOTE:

By the way, I watched this video, and it talks about that, comparing, updating and all. But he has many variables, and doesn’t really go into details so I’ve been trying to understand what he does, but I’m kinda having a lot of trouble doing so, and then at the end he says that its NOT the best way of doing it, so I that also got me confused.

But if anyone has seen that one, and knows how to do it, I don’t need everything that he has there, mostly the updating array, I feel like I can probably find my way from that point.

If you are removing or adding to an array in the middle of your “For Each” code it may cause you problems. Run every thing you need to with the array then clear/add/remove from it. Also it might be easier to just use the built in save game class. Here is a brief video on it.

[quote=“Seed_37, post:3, topic:145372”]

If you are removing or adding to an array in the middle of your “For Each” code it may cause you problems. Run every thing you need to with the array then clear/add/remove from it. Also it might be easier to just use the built in save game class. Here is a brief video on it.

Hi,

Sorry i took a while, I did watch that video, and I watched again in case I missed something. I actually tried that out the first time, but even though I manage to do the saving… I encounter a couple of problems:
I could keep loading the game, and it would spawn actors on top of each other, endlessly, and it would be hard to notice because they occupy the same space, so if later you wanted to delete something, sometimes it would take 4-5 “deletes” depending on how many times they “Loaded”… (If they made a change they didn’t like, they hit load to go back, and that would spawn actors again)
And after making some changes, like deleting some actors, it would update the array, but only adding the new elements, not deleting the ones that were deleted in the game. So it would spawn them the next load.

I was trying to find an example of something, so that I can explained my self better… I’m not really looking to do a For Each constantly, and deleting elements from the array while its doing it…

What I’m looking for is for when the player decides to “Save”… Then it will call all actors (of specific class, or interface) and will go through them, after creating a list of all the actors in the level (with their respective Class, Transform, and Actor) it will compare that array with the “last Saved Slot” and update it. For example:

I have in my scene:
Actor 0, 1, 2, 3, 4, 5

The first time I save, it will create an array with those 6 actors in it, and then save a slot… When I get back, I Load that slot and spawn the same actors in the same position. Here comes my problem:

I continue to play the game, and I decided to change some things, so I delete Actors 1, and 3. Now when I want to save my game, I need to update the array (that was used for saving las slot) to the actual active actors on my level. Otherwise it will save but continue to have Actors 1 and 3 which are deleted right now…

To avoid continuously monitoring every element on the scene, I was thinking of just updating the list once you hit “Save”.
I tried “Deleting” the slot once loaded so it will replace it with all the changes you do while in game, but if they didn’t like the changes they did and they would like to go back to the previews load, I need that to still be there.

My question is: How can I make this -

Save → Call all actors from (tag, Instance, Class, etc) → Compare with array variable → update array (changes, or differences) → Save Slot with Updated Variable
Load → Clear level → Call Variable from Save Slot → Spawn actos from Variable → Update Array Variable

This way it will also allow me to update if one actor was moved, or rotated, it will also later on, allow me to save the materials the user used, the colors and stuff. I believe is the correct logic of building a Save system, but I might be wrong, if there is a different way.

Best Regards!

Edited: When I say “Update Array Variable” at the end of load… I mean probably adding a boolean to each actor that allows the game to “monitor” if they have been spawned, so loading again, it would not re-spawn any “unchanged” actors, but again… Not sure if this is the best way…

It might be a good idea to post some code I am having a little trouble following whats going on and it might be easier to give some advice if we could see what you have so far.

Hi,

I know that would make it a lot easier to visualize what I’m talking about… The problem is I don’t know how to do it, I tried this last couple of days, and before even… but I don’t have that much time working with Unreal, so there is a lot I can’t do yet.

I’m trying to find information, tutorials, guides and stuff about data bases… Like to create a somewhat complex inventory (or in this case a “catalog”) of items, so that is easier to escalate later on… I believe that could also give me the answer for the saving and loading…

If I create a Data Asset (I believe its called un UE4) with all the items, then there will be a way of tracking the items in the level (as if someone is adding or removing items from an inventory) and maybe that way I could update the Array for the Save and Load.

Thank you,
I’ll try to add anything I can come up with in order to help visualizing what I’m trying to accomplish…

Best Regards

How I post images is I use the Snipping tool in windows.

Then on the Post window click the advanced options.

Then Click on the Image Tab.

Then Click on the upload Tab.

Capture7.png

Then Click on the Brows Button, find your image and click the Open button.

Capture8.PNG

Then you have to click the upload to server button.

Capture9.PNG

Then you click ok.

Capture10.PNG

Also one of my go to tutorial series is the “HTF do I” and “WTF is” by Mathew Wadstein at

So for Arrays or Data Sets I would just google WTF is Arrays or WTF is Data Sets and you should get a short youtube video with a detailed explanation on what this Blueprint node is, how it works and how to apply it in your game.