Save actor's destroyed(picked) state between levels

I am trying to figure a way through blueprints to save actors availability based on their picked up status.I can find nodes to save information like location in savegame slots but not destroyed status.
Gameplay is:

  1. Load Map-1.It has all the unpicked items.

  2. Through overlap destroy the actors that were touched by my Player.

  3. Later my Player reaches Map-2 that has its own unpicked items. There is a door that tells the Player to go back to Map-1.

  4. Go back to Map-1.Objects that were picked(destroyed) must not be loaded again.Only the unpicked ones.

Please help me on how to approach this. If its easier for you tell me an approach with a single object not multiple that will require Array Variables.But you will be more than welcomed to tell me the Array approach because its inevitable that there will be more than one same actor on a Map.

thanks for your time

Alexander Moschopoulos

I found a solution for a single object! I just had to make a “picked” boolean variable to SaveGame file and then through a branch in LevelBlueprint i defined if it will be spawned through this. Now the next step is to make a setup for multiple objects through arrays.Any help will be welcomed :slight_smile:

You could make a struct called item data and then in the struct have several variables like name type and so forth. One of those variables can be destroyed and would be a bool. Then in the items actor blueprint you have for the item you want to pickup make a new variable of type “item data” which is the struct you created and then set the defaults to that variable like “first aid” “type is pickup” and destroyed “false”.
Add all item structs to an array of structs called items at begin play.
when the player picks up the item with a line trace by channel set the destroyed bool to true for the actor that was line traced.
Save that data using the save game blueprints.
Then when level one is reloaded have a for each loop with the array “items” you created run through a branch that calls the “destroyed” bool on the item structs. If it returns true then destroy that actor from the level.

thank you very much! I ll try it

No problem!

nightmareyahoo
Could you please post a few images to help follow this, I unfortunately have a slight issue understanding stuff in righting, so images would be alot more helpfull

Sure thing.
First you need to right click in the content browser and create a Structure called “S_Item_Data” which will contain all of the dynamic data for each item in your game. This wont list specific data like the items name, but will be a placeholder to add the items name and so forth later.

In that struct you will need to add a bool and name it “Is Destroyed in world”

Next you will need to make a new blueprint Actor. This will be named Master Item to be a parent for your actual game items like a first aid kit or weapon and so forth. You do this so that when you make a child of the master item, it will keep all of the variables in the master.
In the master item blueprint make a variable of type “The struct you made before”. Mine was called S_Item_Data.

You can see on the upper right that the blueprint now has all of the item data from the struct and you can change those placeholders with any information you want.

Next, right click on the master item blueprint and create a child of that blueprint.
In the child rename the item whatever you want in the S_Item_Data area in the upper right hand corner. Add your mesh for the item to be seen in game.

Now you need to make a pickup function. I’ve made one in the image below.

At the end you’ll see the Is Destroyed in World bool being set for that specific actor in the level and then being destroyed when picked up.

You must then save that data in the Save Game blueprint that you make for each item.

Now in the level blueprint make a for each loop that checks each item in the level to see whether it has been destroyed. It doesn’t matter if its the first time the player has opened the level or not because they wont have set any of the Is Destroyed bools yet.

When the level is loaded it will check the items Destroyed status. If it has been destroyed before, it will then destroy it in the level once it is reloaded on Begin Play as seen in the image below.

Where it says that you need to add the items in the level to an array, it just means that to check all of the items they need to be added to an array at Begin play to an array of type Actor or Master ITems. This will allow the for each loop to check each item in that array for the Is Destroyed bool.

I hope that was at least a little bit clear :slight_smile:
Cheers!

I posted a reply below but I think it was too many characters to make as a reply to a comment or something? either way it wouldn’t let me post it as a reply to you directly, but I hope it helps!

You can definitely just add a bool for Is Destroyed in the items blueprint and set it to true when the item is picked up without a struct or master item, but if you have an inventory system or have more than just a few items in the level it’s definitely more efficient to use structures and a master item. It will handle the item data automatically for each item and prevents really long blueprints and having to repeat code for each individual item; because it inherits from a master item.

“You must then save that data in the Save Game blueprint that you make for each item.”

sorry for being a total idiot mate and thanks for all the help but how do i save that item data?
I have a basic save setup and its able to save the items i picked up in the inventory but evertime i reopen the level my items are still in my inventory but the pickups i made from the child BP of the master item BP keep respawning :frowning:

Hey it’s no problem. Can you give me an hour or so to get a function built? It’s a little trickier than it sounds because once the actor is destroyed it no longer has logic working on it so you have to add it to a reference array and then use the reference to save the data and load the data.

No probs at all mate, i appreciate the help, there are so many blueprints for games, characters, enemies, items, save instance and game instance its tough to know what goes where especially for items.
its probly something sooo simple that im missing lol

That would be great mate. the item struct and save system im using so far seem to work fine
i set the game in my character bp to save an load when i possess or unpossess my character and so far everything saves, but i havent been able to stop the items i picked up from respawning over when i reopen the level

Okay so it took me a little longer than I thought it would; Apologies on that one :slight_smile:
I actually made a mistake in the previous method. Logically it will not work because that actor has been destroyed and no logic can be pulled from a destroyed actor. BUT keep the item data structure and workflow for creating in game items because having that item data and parent-child relationship between master items and actual items is very important for an inventory system and you will need them later!
I will post the new method below and try to explain why this way is needed to save destroyed actors.

A good practice is to create empty game actors and add them to your level to hold data. That way you can call that data from anywhere in game and it isn’t all in one blueprint. Good code is simple and layered like a machine with many parts(or functions) rather than one part with too many functions inside of it. This is the reason I’m using this particular method.

Firstly, you need to create a new blueprint actor named: “Items_Destroyed”
This actor will not have a mesh and you wont see it in game, but it will hold data to save and call from in the level blueprint.

Next open that blueprint and create a new variable of type Actor (reference) and make it an array. Name it “Items_Destroyed”. Exit out of the Blueprint.

Add the Items_destroyed ACTOR to the level by dragging it into the viewport.
Next, in your pickup function (with the line trace), you need to add some code.

After that you need to add code to your Save Game Blueprint (if you’ve made one, if not, right click in the content browser and create a blueprint, search for save game, and select it to create a save game blueprint).

In the save game blueprint (Mine is called SAVE) create a variable of type Actor (reference) and make it an array. Name it Destroyed_Actors (I’ve chosen to name it differently than the Items_Destroyed variable that we made before because it helps to keep them straight when saving and loading). Exit out of the blueprint.

Next you will need to add code to your game save function.

And add code to your load function.

Finally you will need to add a function at Begin Play in the level blueprint. This will destroy all the actors saved and loaded in Items Destroyed.

This is done by selecting the Items_Destroyed actor that you added to your level (make sure to click on it in the actual level). Then open the level blueprint and, in the event graph, add a reference to that actor by right clicking and (with context sensitive checked) clicking create a reference to “Items_Destroyed”.

Next add the code in the image below. This will loop though and delete all the actors that were saved.
Note:
There is a delay at the beginning to make sure that all of the Actors in that array have loaded before trying to destroy them. The delay isn’t noticeable in game.

Yeah, structs work great for data management! But it will not delete the actors because when you check if the Bool IsDestroyed is true or false, it is checking the STRUCT data from an actor in an array NOT the actor from the actual level and, therefore, won’t destroy anything.

I’m sorry for the wrong answer before, I hadn’t actually tested it outside of a limited situation before now. The method below is completely dynamic and will work for all levels.

Note: you can make new arrays in the Items_Destroyed blueprint for each level and call them from the level blueprint to only destroy the actors from that specific level. Just remember to add that array to the save game blueprint and save and load that array correctly :slight_smile:

Also, you can remove the IsDestroyed bool from the struct now, since it won’t actually work in game.

If any of that doesn’t make sense let me know cause there’s a lot going on in that :slight_smile:

Thanks Mate I’m workin On addin all this now, ill let ya know how it goes.
Does this mean the “items_destroyed” bp will be my new master item for pick ups so they dont respawn?